package com.mission.schedule.activity;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.appwidget.AppWidgetManager;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.content.res.AssetFileDescriptor;
import android.graphics.Color;
import android.media.MediaPlayer;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.Vibrator;
import android.support.annotation.Nullable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.AnimationUtils;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.android.volley.AuthFailureError;
import com.android.volley.DefaultRetryPolicy;
import com.android.volley.Request.Method;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.mission.schedule.CommonDialog.CalenderColorDialog;
import com.mission.schedule.CommonDialog.CalenderFlagDialog;
import com.mission.schedule.CommonDialog.MonthActivityAddDialog;
import com.mission.schedule.CommonDialog.MonthFragmentAddDialog;
import com.mission.schedule.CommonDialog.SixNewTaskDialog;
import com.mission.schedule.CommonViewController.CommonSearchTagActivity;
import com.mission.schedule.R;
import com.mission.schedule.applcation.App;
import com.mission.schedule.bean.CalenderNoteBean;
import com.mission.schedule.bean.MySchBean;
import com.mission.schedule.bean.WBA_FindFunctionMy;
import com.mission.schedule.bean.qd606.NoteTitleDetailBean;
import com.mission.schedule.clock.QueryAlarmData;
import com.mission.schedule.constants.Const;
import com.mission.schedule.constants.ShareFile;
import com.mission.schedule.constants.URLConstants;
import com.mission.schedule.entity.CLRepeatTable;
import com.mission.schedule.entity.LocateAllNoticeTable;
import com.mission.schedule.entity.ScheduleTable;
import com.mission.schedule.fragment.MyScheduleFragment;
import com.mission.schedule.my160920.FrendLyActivity;
import com.mission.schedule.my160920.widget.EditTextC;
import com.mission.schedule.newAdapter.CalenderAdapter;
import com.mission.schedule.newAdapter.MothViewAdapter;
import com.mission.schedule.sinaadd.BaseDialog;
import com.mission.schedule.utils.CalendarChange;
import com.mission.schedule.utils.DateUtil;
import com.mission.schedule.utils.InWeekUtils;
import com.mission.schedule.utils.MyLinearLayout;
import com.mission.schedule.utils.MyViewPager;
import com.mission.schedule.utils.RepeatSetChildEndUtils;
import com.mission.schedule.utils.SharedPrefUtil;
import com.mission.schedule.utils.StringUtils;
import com.mission.schedule.utils.UriUtils;
import com.nostra13.universalimageloader.core.ImageLoader;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import de.greenrobot.event.EventBus;

import static com.mission.schedule.calendar.CalendarFactory.getMonthOfDayList;

public class MonthViewActivity extends Activity {

    int opeartPosition = -1;
    private String postpone = "0";// 顺延
    String date = "";
    private MothViewAdapter adapter = null;
    ArrayList<Map<String, String>> mList = new ArrayList<>();
    RecyclerView recyclerView;
    public static List<Map<String, String>> schIDList = new ArrayList<>();
    SharedPrefUtil sharedPrefUtil = null;
    String userid = "";
    Context context;
    App application = App.getDBcApplication();
    InWeekUtils inWeekUtils = new InWeekUtils();
    RepeatSetChildEndUtils repeatSetChildEndUtils = new RepeatSetChildEndUtils();
    String soundstate;
    String wakestate;
    private Vibrator vibrator;
    String untaskend;
    int newopeartType = 0;
    TextView edit_add;
    InputMethodManager imm;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.monthviewdialog);
        imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

        date = getIntent().getStringExtra("date");
        newopeartType = getIntent().getIntExtra("newopeartType", 0);

        context = this;
        sharedPrefUtil = new SharedPrefUtil(context, ShareFile.USERFILE);
        userid = sharedPrefUtil.getString(context, ShareFile.USERFILE, ShareFile.USERID, "");
        vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
        recyclerView = findViewById(R.id.recyclerView);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.setItemAnimator(new DefaultItemAnimator());
        TextView title = findViewById(R.id.title);
        LinearLayout close = findViewById(R.id.close);
        edit_add = findViewById(R.id.edit_add);

        int day_c = DateUtil.days(date);
        String day = "";
        if (day_c == 0) {
            day = "今天";
        }
        if (day_c == 1) {
            day = "明天";
        }
        if (day_c == 2) {
            day = "后天";
        }
        if (day_c == -1) {
            day = "昨天";
        }
        if (day_c == -2) {
            day = "前天";
        }
        if (day_c > 2) {
            day = day_c + "天后";
        }
        if (day_c < -2) {
            day = day_c + "天前";
        }
        title.setText(date.substring(5, date.length()) + " " + DateUtil.Week(date) + " " + day);

        close.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

//        edit_add.setInputType(EditorInfo.TYPE_CLASS_TEXT);
//        edit_add.setImeOptions(EditorInfo.IME_ACTION_SEND);
//        edit_add.setImeActionLabel("保存", EditorInfo.IME_ACTION_SEND);
//        edit_add.setFocusable(false);
//        edit_add.setEnabled(false);
        edit_add.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MonthFragmentAddDialog dialog = new MonthFragmentAddDialog(MonthViewActivity.this,
                        R.style.dialog_translucent, getWindowManager(), date, newopeartType);
                dialog.show();
                dialog.setCallBack(new MonthFragmentAddDialog.CallBack() {
                    @Override
                    public void reminderEditTime() {
                        try {
                            loadData(3, "");
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                });
            }
        });
//        edit_add.setOnEditorActionListener(new TextView.OnEditorActionListener() {
//            @Override
//            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
//                if (actionId == EditorInfo.IME_ACTION_SEND) {
//                    if (edit_add.getText().toString().length() > 0) {
//                        App.getDBcApplication().insertScheduleData(edit_add.getText().toString(),
//                                date, "23:59", 0, 0, 0, 0, 0, 0, 0,
//                                date + " 23:59:00", "", 2, DateUtil.nowTime2(), "0", 0, "", "",
//                                1, 0, 0, "完成任务", "g_88", "", 0, 0, 0, "", "", 0, 0, 0, 0, "0", "0", "0");
//                        QueryAlarmData.writeAlarm(context);
//                        Toast.makeText(context, "新建成功", Toast.LENGTH_SHORT).show();
//                        Intent intent = new Intent(Const.SHUAXINDATA);
//                        intent.putExtra("data", "success");
//                        intent.putExtra("index", 1);
//                        intent.putExtra("what", 2);
//                        context.sendBroadcast(intent);
//                        sharedPrefUtil.putString(context, ShareFile.USERFILE, ShareFile.IS_MONTH_RE, "1");
//                        edit_add.setText("");
//                    }
//                    imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
//                    loadData(3, "");
//                    return true;
//                }
//                return false;
//            }
//        });

        loadData(3, "");
        setDataToAdapter();
    }

    List<Map<String, String>> ulist = new ArrayList<>();
    List<Map<String, String>> dblist = new ArrayList<>();

    private void loadData(int opeartType, String opeartSchID) {
        untaskend = sharedPrefUtil.getString(context, ShareFile.USERFILE, ShareFile.UNTASKEND, "0");// 0显示 1不显示
        mList.clear();
        ulist.clear();
        dblist.clear();
        List<Map<String, String>> newList = new ArrayList<>();
        try {
            switch (newopeartType) {
                case -1://以前
                    ulist.addAll(App.getDBcApplication().queryAllSchData(22, 0, 0));
                    ulist.addAll(App.getDBcApplication().queryAllSchData(23, 0, 0));
                    break;
                case -2:
                    ulist.addAll(App.getDBcApplication().queryAllSchData(25, 0, 0));
                    ulist.addAll(App.getDBcApplication().queryAllSchData(26, 0, 0));
                    ulist.addAll(App.getDBcApplication().queryAllSchData(27, 0, 0));
                    ulist.addAll(App.getDBcApplication().queryAllSchData(28, 0, 0));
                    ulist.addAll(App.getDBcApplication().queryAllSchData(29, 0, 0));
                    ulist.addAll(App.getDBcApplication().queryAllSchData(30, 0, 0));
                    break;
                case -3:
                    ulist.addAll(App.getDBcApplication().queryAllSchData(-6, 0, 0));
                    break;
                case -4:
                    ulist.addAll(App.getDBcApplication().queryAllSchData(66, 0, 0));
                    ulist.addAll(App.getDBcApplication().queryAllSchData(67, 0, 0));
                    ulist.addAll(App.getDBcApplication().queryAllSchData(68, 0, 0));
                    ulist.addAll(App.getDBcApplication().queryAllSchData(69, 0, 0));
                    ulist.addAll(App.getDBcApplication().queryAllSchData(70, 0, 0));
                    ulist.addAll(App.getDBcApplication().queryAllSchData(71, 0, 0));
                    break;
                case -6:
                case -7:
                case -8:
                case -9:
                case -10:
                case -11:
                case -12:
                    newopeartType = Math.abs(newopeartType) - 5;

                    ulist.addAll(App.getDBcApplication().queryAllSchData(50, 0, newopeartType));
                    ulist.addAll(App.getDBcApplication().queryAllSchData(51, 0, newopeartType));
                    ulist.addAll(App.getDBcApplication().queryAllSchData(52, 0, newopeartType));
                    ulist.addAll(App.getDBcApplication().queryAllSchData(53, 0, newopeartType));
                    ulist.addAll(App.getDBcApplication().queryAllSchData(54, 0, newopeartType));
                    ulist.addAll(App.getDBcApplication().queryAllSchData(55, 0, newopeartType));
                    ulist.addAll(App.getDBcApplication().queryAllSchData(50, 0, 100 + newopeartType));
                    ulist.addAll(App.getDBcApplication().queryAllSchData(51, 0, 100 + newopeartType));
                    ulist.addAll(App.getDBcApplication().queryAllSchData(52, 0, 100 + newopeartType));
                    ulist.addAll(App.getDBcApplication().queryAllSchData(53, 0, 100 + newopeartType));
                    ulist.addAll(App.getDBcApplication().queryAllSchData(54, 0, 100 + newopeartType));
                    ulist.addAll(App.getDBcApplication().queryAllSchData(55, 0, 100 + newopeartType));

                    break;
                default:
                    if (!sharedPrefUtil.getString(this, ShareFile.USERFILE, ShareFile.TYPEUID, "").isEmpty()) {
                        String uid = sharedPrefUtil.getString(this, ShareFile.USERFILE, ShareFile.TYPEUID, "9999991");
                        ulist = App.getDBcApplication().queryCalenderData("", Integer.valueOf(uid));
                    } else {
                        dblist = App.getDBcApplication().queryCalenderData(date, 3);
                        ulist = App.getDBcApplication().queryCalenderData(date, 2);
                    }
                    break;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        newList.clear();
        newList.addAll(dblist);
        newList.addAll(ulist);

        for (Map<String, String> map : newList) {
            if (map.get(ScheduleTable.schDate).equals(date)) {
                mList.add(map);
            }
        }
        uncount = dblist.size();
        todaycount = ulist.size();

        if (!opeartSchID.isEmpty()) {
            for (int i = 0; i < mList.size(); i++) {
                if (opeartSchID.equals(mList.get(i).get(ScheduleTable.schID))) {
                    opeartPosition = i;
                    break;
                }
            }
        }


        if (opeartType == 3) {
            setDataToAdapter();
        } else if (opeartType == 0) {
            adapter.addCalender(opeartPosition, mList.get(opeartPosition), uncount, todaycount, 0, 0, 0, "", "1");
        } else if (opeartType == 1) {
            if (untaskend.equals("0")) {
                adapter.notifyDataSetChanged();
            } else {
                adapter.deleteCaledner(opeartPosition, uncount, todaycount, 0, 0, 0, "", "1");
            }
        } else if (opeartType == 2) {
            if (untaskend.equals("0")) {
                adapter.notifyDataSetChanged();
            } else {
                adapter.updateCalender(opeartPosition, mList.get(opeartPosition));
            }
        } else {
            adapter.notifyDataSetChanged();
        }
        sharedPrefUtil.putString(context, ShareFile.USERFILE, ShareFile.IS_MONTH_RE, "1");
        sharedPrefUtil.putString(context, ShareFile.USERFILE, ShareFile.SCHTYPE, "1");
        MainActivity.instance.loadCount();
    }

    int uncount = 0;
    int todaycount = 0;

    private void setDataToAdapter() {

        adapter = new MothViewAdapter(this, mList, handler, uncount, todaycount, 0, 0, 0, "", "1", 0);
        recyclerView.setAdapter(adapter);
        adapter.notifyDataSetChanged();
    }

    Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            Intent intent = null;
            final Map<String, String> mMap = (Map<String, String>) msg.obj;
            final int position = msg.arg1;
            if (Integer.parseInt(mMap.get(ScheduleTable.schID)) < 0) {
                if (schIDList != null && schIDList.size() > 0) {
                    for (int i = 0; i < schIDList.size(); i++) {
                        Object[] indexStr = schIDList.get(i).keySet().toArray();
                        String index = indexStr[0].toString();
                        if (Integer.parseInt(mMap.get(ScheduleTable.schID)) == Integer.parseInt(index)) {
                            mMap.put(ScheduleTable.schID, schIDList.get(i).get(index));
                            break;
                        }
                    }
                }
            }
            if (sharedPrefUtil.getString(context, ShareFile.USERFILE, ShareFile.TYPEUID, "").isEmpty()) {
                switch (msg.what) {
                    case -1:
                        dialogDetailOnClick(mMap, 0, position);
                        break;
                    case 0:// 点击菜单(详情菜单)
                        if (mList.size() > 0) {
                            Map<String, String> map = App.getDBcApplication().QueryhongFuData(mList.get(position).get(ScheduleTable.schRepeatID));
                            if (map != null) {
                                if (!map.get(CLRepeatTable.remark2).isEmpty()) {
                                    WBA_FindFunctionMy.ListBean bean = App.getDBcApplication().get_tb_function_my(map.get(CLRepeatTable.remark2));
                                    if (!bean.url.isEmpty()) {Intent x = new Intent(MonthViewActivity.this, WebViewActivity.class);
                                        x.putExtra("url", bean.url);
                                        x.putExtra("remark2", bean.id + "");
                                        x.putExtra("fun_id", bean.id + "");
                                        x.putExtra("schID", mMap.get(ScheduleTable.schID));
                                        startActivityForResult(x, 100);
                                    } else {
                                        detail(mMap, intent, position);
                                    }
                                } else if (map.get(CLRepeatTable.repContent).length() > 2 && map.get(CLRepeatTable.repContent).substring(0,2).equals("#%")) {
                                    List<CalenderNoteBean.PageBean.ItemsBean> list =
                                            App.getDBcApplication().getCalenderNoteDetailData(userid, map.get(CLRepeatTable.repSourceDesc), false);
                                    if (list.size() >= 1 && UriUtils.isUrl(list.get(0).contents)) {
                                        Intent x = new Intent(context, WebViewActivity.class);
                                        x.putExtra("url", list.get(0).contents);
                                        x.putExtra("fun_id", "");
                                        x.putExtra("remark2", map.get(CLRepeatTable.repContent));
                                        x.putExtra("schID", mMap.get(ScheduleTable.schID));
                                        startActivityForResult(x, 100);
                                    } else {
                                        detail(mMap, intent, position);
                                    }
                                } else {
                                    detail(mMap, intent, position);
                                }
                            } else if(mMap.get(ScheduleTable.schRemark6) != null){
                                WBA_FindFunctionMy.ListBean bean = App.getDBcApplication().get_tb_function_my(mMap.get(ScheduleTable.schRemark6));
                                if (bean != null && !bean.url.isEmpty()) {
                                    Intent x = new Intent(context, WebViewActivity.class);
                                    x.putExtra("url", bean.url);
                                    x.putExtra("remark2", bean.id + "");
                                    x.putExtra("fun_id", bean.id + "");
                                    x.putExtra("schID", mMap.get(ScheduleTable.schID));
                                    startActivityForResult(x, 100);
                                } else if (mMap.get(ScheduleTable.schContent).length() > 2 && mMap.get(ScheduleTable.schContent).substring(0,2).equals("#%")) {
                                    List<CalenderNoteBean.PageBean.ItemsBean> list =
                                            App.getDBcApplication().getCalenderNoteDetailData(userid, mMap.get(ScheduleTable.schSourceDesc), false);
                                    if (list.size() >= 1 && UriUtils.isUrl(list.get(0).contents)) {
                                        Intent x = new Intent(context, WebViewActivity.class);
                                        x.putExtra("url", list.get(0).contents);
                                        x.putExtra("fun_id", "");
                                        x.putExtra("remark2", mMap.get(ScheduleTable.schContent));
                                        x.putExtra("schID", mMap.get(ScheduleTable.schID));
                                        startActivityForResult(x, 100);
                                    } else {
                                        detail(mMap, intent, position);
                                    }
                                } else {
                                    detail(mMap, intent, position);
                                }
                            } else {
                                detail(mMap, intent, position);
                            }
                        }
                        break;

                    case 2:// 设为结束deleteItem
                        if (msg.arg2 == 1) {
                            if (Integer.valueOf(mList.get(position).get(ScheduleTable.schcRecommendId)) > 0
                                    && Integer.valueOf(mList.get(position).get(ScheduleTable.schAID)) == 0) {
                                if (!mList.get(position).get(ScheduleTable.schRepeatID).equals("0")) {
                                    sharedPrefUtil.putString(context, ShareFile.USERFILE, ShareFile.UPLOADTYPE, "1");
                                } else {
                                    sharedPrefUtil.putString(context, ShareFile.USERFILE, ShareFile.UPLOADTYPE, "0");
                                }
                            } else {
                                sharedPrefUtil.putString(context, ShareFile.USERFILE, ShareFile.UPLOADTYPE, "1");
                            }

                            if (mList.get(position).get(ScheduleTable.schSourceType).toString().equals("3")) {
                                if (mList.get(position).get(ScheduleTable.schpisEnd).toString().equals("0")) {
                                    SixNewTaskDialog sixNewTaskDialog = new SixNewTaskDialog(context, R.style.dialog_translucent1,
                                            getWindowManager(), 2, mList.get(position).get(ScheduleTable.schSourceDesc)
                                            , mList.get(position).get(ScheduleTable.schcRecommendId));
                                    sixNewTaskDialog.show();
                                    sixNewTaskDialog.setCallBack(new SixNewTaskDialog.CallBack() {
                                        @Override
                                        public void NewTaskDialogSure() {
                                            endCalender(mMap, position);
                                        }

                                        @Override
                                        public void NewTaskDialogCancel() {
                                            adapter.notifyDataSetChanged();
                                        }
                                    });
                                } else {
                                    adapter.notifyDataSetChanged();
                                }
                            } else {
                                endCalender(mMap, position);
                            }
                        } else {
                            if (Integer.valueOf(mList.get(position).get(ScheduleTable.schcRecommendId)) > 0
                                    && Integer.valueOf(mList.get(position).get(ScheduleTable.schAID)) == 0) {
                                if (!mList.get(position).get(ScheduleTable.schRepeatID).equals("0")) {
                                    sharedPrefUtil.putString(context, ShareFile.USERFILE, ShareFile.UPLOADTYPE, "1");
                                    endCalender(mMap, position);
                                } else {
                                    sharedPrefUtil.putString(context, ShareFile.USERFILE, ShareFile.UPLOADTYPE, "0");
                                    if (mList.get(position).get(ScheduleTable.schSourceType).toString().equals("3")) {
                                        if (mList.get(position).get(ScheduleTable.schpisEnd).toString().equals("0")) {
                                            SixNewTaskDialog sixNewTaskDialog = new SixNewTaskDialog(context, R.style.dialog_translucent1,
                                                    getWindowManager(), 0, mList.get(position).get(ScheduleTable.schSourceDesc)
                                                    , mList.get(position).get(ScheduleTable.schcRecommendId));
                                            sixNewTaskDialog.show();
                                            sixNewTaskDialog.setCallBack(new SixNewTaskDialog.CallBack() {
                                                @Override
                                                public void NewTaskDialogSure() {
                                                    endCalender(mMap, position);
                                                }

                                                @Override
                                                public void NewTaskDialogCancel() {
                                                    adapter.notifyDataSetChanged();
                                                }
                                            });
                                        } else {
                                            adapter.notifyDataSetChanged();
                                        }
                                    } else {
                                        deleteItem(mMap, position);
                                    }
                                }

                            } else {
                                sharedPrefUtil.putString(context, ShareFile.USERFILE, ShareFile.UPLOADTYPE, "1");
                                endCalender(mMap, position);
                            }
                        }
                        break;

                    case 3:// 删除
                        sharedPrefUtil.putString(context, ShareFile.USERFILE, ShareFile.DELETETYPE, "1");
                        try {
                            if (Integer.valueOf(mList.get(position).get(ScheduleTable.schcRecommendId)) > 0
                                    && Integer.valueOf(mList.get(position).get(ScheduleTable.schAID)) == 0) {
                                if (!mList.get(position).get(ScheduleTable.schRepeatID).equals("0")) {
                                    sharedPrefUtil.putString(context, ShareFile.USERFILE, ShareFile.UPLOADTYPE, "1");
                                    deleteCalender(mMap, 0, position);
                                } else {
                                    sharedPrefUtil.putString(context, ShareFile.USERFILE, ShareFile.UPLOADTYPE, "0");
                                    if (mList.get(position).get(ScheduleTable.schSourceType).toString().equals("3") ||
                                            mList.get(position).get(ScheduleTable.schSourceType).toString().equals("4") ||
                                            mList.get(position).get(ScheduleTable.schSourceType).toString().equals("5")) {
                                        SixNewTaskDialog sixNewTaskDialog = new SixNewTaskDialog(context, R.style.dialog_translucent1,
                                                getWindowManager(), mList.get(position).get(ScheduleTable.schSourceType).toString().equals("3") ? 1 : 3,
                                                mList.get(position).get(ScheduleTable.schSourceDesc)
                                                , mList.get(position).get(ScheduleTable.schcRecommendId));
                                        sixNewTaskDialog.show();
                                        sixNewTaskDialog.setCallBack(new SixNewTaskDialog.CallBack() {
                                            @Override
                                            public void NewTaskDialogCancel() {
                                                adapter.notifyDataSetChanged();
                                            }

                                            @Override
                                            public void NewTaskDialogSure() {
                                                deleteCalender(mMap, 0, position);
                                            }
                                        });
                                    } else {
                                        alertDeleteDialog(mMap, 0, position);
                                    }
                                }
                            } else {
                                sharedPrefUtil.putString(context, ShareFile.USERFILE, ShareFile.UPLOADTYPE, "1");
                                deleteCalender(mMap, 0, position);
                            }

                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        break;
                    case 4:// 跳到日历页面
                        intent = new Intent(context, DateCalendarActivity.class);
                        intent.putExtra("myschedulefragment", "0");
                        intent.putExtra("sourse", 0);
                        intent.putExtra("dateTime", mMap.get(ScheduleTable.schDate));
                        intent.putExtra("postpone", postpone);
                        intent.putExtra("openState", mMap.get(ScheduleTable.schOpenState));
                        intent.putExtra("ringcode", mMap.get(ScheduleTable.schRingCode));
                        intent.putExtra("schIsAlarm", mMap.get(ScheduleTable.schIsAlarm));
                        startActivity(intent);
                        break;
                    case 7://收到的任务更多
                        dialogDetailOnClick(mMap, 0, position);
                        break;
                }
            }
        }
    };


    MediaPlayer mediaPlayer = new MediaPlayer();
    AssetFileDescriptor fileDescriptor = null;

    private void dialogDetailOnClick(Map<String, String> mMaps, int setType,
                                     final int position) {
        final Dialog dialog = new Dialog(context, R.style.dialog_translucent);
        Window window = dialog.getWindow();
        WindowManager.LayoutParams params = window.getAttributes();// 获取LayoutParams
//        params.alpha = 0.93f;
        window.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL);
        window.setAttributes(params);// 设置生效

        LayoutInflater fac = LayoutInflater.from(context);
        View more_pop_menu = fac.inflate(R.layout.dialog_calender_new_detail, null);
        dialog.setCanceledOnTouchOutside(true);
        dialog.setContentView(more_pop_menu);
        params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        params.width = getWindowManager().getDefaultDisplay().getWidth() - 30;
        dialog.show();

        final Map<String, String> mMap = mMaps;


        List<View> viewList = new ArrayList<View>();


        MyViewPager myViewPager = more_pop_menu.findViewById(R.id.viewpager_detail);

        View viewOne = LayoutInflater.from(context).inflate(R.layout.dialog_calender_new_detail_item1, null);
        View viewTwo = LayoutInflater.from(context).inflate(R.layout.dialog_calender_new_detail_item2, null);
//        applyBlur(viewOne);
//        applyBlur(viewTwo);

        final Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        String today = DateUtil.formatDate(calendar.getTime());
        calendar.set(Calendar.DAY_OF_MONTH,
                calendar.get(Calendar.DAY_OF_MONTH) + 1);
        String tomorrow = DateUtil.formatDate(calendar.getTime());

        final int id = Integer.parseInt(mMap.get(ScheduleTable.schID));


        final Map<String, String> map = App.getDBcApplication().QueryStateData(
                Integer.parseInt(mMap.get(ScheduleTable.schRepeatID)));

        final Intent intent = new Intent();

        final MySchBean mySchBean = new MySchBean();
        mySchBean.schID = mMap.get(ScheduleTable.schID);
        mySchBean.schContent = mMap.get(ScheduleTable.schContent);
        mySchBean.schDate = mMap.get(ScheduleTable.schDate);
        mySchBean.schTime = mMap.get(ScheduleTable.schTime);
        mySchBean.schIsAlarm = mMap.get(ScheduleTable.schIsAlarm);
        mySchBean.schBeforeTime = mMap.get(ScheduleTable.schBeforeTime);
        mySchBean.schDisplayTime = mMap.get(ScheduleTable.schDisplayTime);
        mySchBean.schIsPostpone = mMap.get(ScheduleTable.schIsPostpone);
        mySchBean.schIsImportant = mMap.get(ScheduleTable.schIsImportant);
        mySchBean.schColorType = mMap.get(ScheduleTable.schColorType);
        mySchBean.schIsEnd = mMap.get(ScheduleTable.schIsEnd);
        mySchBean.schCreateTime = mMap.get(ScheduleTable.schCreateTime);
        mySchBean.schTags = mMap.get(ScheduleTable.schTags);
        mySchBean.schSourceType = mMap.get(ScheduleTable.schSourceType);
        mySchBean.schSourceDesc = mMap.get(ScheduleTable.schSourceDesc);
        mySchBean.schSourceDescSpare = mMap.get(ScheduleTable.schSourceDescSpare);
        mySchBean.schRepeatID = mMap.get(ScheduleTable.schRepeatID);
        mySchBean.schRepeatDate = mMap.get(ScheduleTable.schRepeatDate);
        mySchBean.schUpdateTime = mMap.get(ScheduleTable.schUpdateTime);
        mySchBean.schUpdateState = mMap.get(ScheduleTable.schUpdateState);
        mySchBean.schOpenState = mMap.get(ScheduleTable.schOpenState);
        mySchBean.schRepeatLink = mMap.get(ScheduleTable.schRepeatLink);
        mySchBean.schRingDesc = mMap.get(ScheduleTable.schRingDesc);
        mySchBean.schRingCode = mMap.get(ScheduleTable.schRingCode);
        mySchBean.schcRecommendName = mMap.get(ScheduleTable.schcRecommendName);
        mySchBean.schRead = mMap.get(ScheduleTable.schRead);

/*****第一页****/

        final TextView fenlei = viewOne.findViewById(R.id.fenlei);
        final TextView day = viewOne.findViewById(R.id.day);
        final TextView week = viewOne.findViewById(R.id.week);
        final TextView month = viewOne.findViewById(R.id.month);
        final TextView copy_content = viewOne.findViewById(R.id.copy_content);
        final TextView important = viewOne.findViewById(R.id.important);
        final TextView color_tv = viewOne.findViewById(R.id.color_tv);

        int colortype = Integer.parseInt(mMap.get(ScheduleTable.schColorType));
        final String colorname = application.QueryTagNameData(colortype).get("ctgText");

        final LinearLayout st_ll = viewOne.findViewById(R.id.st_ll);
        final LinearLayout copy_ll = viewOne.findViewById(R.id.copy_ll);
        final LinearLayout time_ll = viewOne.findViewById(R.id.time_ll);
        if (mMap.get(ScheduleTable.schSourceType).equals("3")
                || mMap.get(ScheduleTable.schSourceType).equals("4")
                || mMap.get(ScheduleTable.schSourceType).equals("5")) {
            copy_ll.setVisibility(View.GONE);
            time_ll.setVisibility(View.GONE);
            st_ll.setVisibility(View.VISIBLE);
        }
        if (colorname.equals("未分类")) {
            fenlei.setText("\"" + colorname + "\"\n分类设置");
        } else {
            fenlei.setText("\"" + colorname + "\"\n分类设置");
        }

        if (mMap.get(ScheduleTable.schDate).compareTo(DateUtil.nowTodyTime()) <= 0) {
            day.setText("推到明天");
            week.setText("推到下周");
            month.setText("推到下月");
        } else {
            day.setText("推后一天");
            week.setText("推后一周");
            month.setText("推后一月");
        }

        color_tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
                CalenderColorDialog colorDialog = new CalenderColorDialog(context, R.style.dialog_translucent,
                        getWindowManager(), mMap.get(ScheduleTable.schID), 0);
                colorDialog.show();
                colorDialog.setCallBack(new CalenderColorDialog.CallBack() {
                    @Override
                    public void reminderEditTime(String color_position_f, String color_position) {
                        loadData(2, mMap.get(ScheduleTable.schID));
                        adapter.notifyDataSetChanged();
                    }
                });
            }
        });

        day.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                try {
                    updateFocusStateSch(mMap, ScheduleTable.schFocusState);
                    String date = inWeekUtils.AfterOneDay(mMap.get(ScheduleTable.schDate));
                    App.getDBcApplication().updateScheduleDateData(id, date, mMap.get(ScheduleTable.schTime));
                    App.getDBcApplication().updateSchReadData(
                            Integer.parseInt(mMap.get(ScheduleTable.schID)), 0);
                    App.getDBcApplication().updateSchRepeatLinkData(
                            Integer.parseInt(mMap.get(ScheduleTable.schID)), 0);
                    if (!"".equals(mMap.get(ScheduleTable.schRepeatDate))
                            || !"0".equals(mMap.get(ScheduleTable.schRepeatLink))) {
                        if (map != null) {
                            String repdate = mMap
                                    .get(ScheduleTable.schRepeatDate);
                            String lastdate = StringUtils.getIsStringEqulesNull(map
                                    .get(CLRepeatTable.repDateOne));
                            String nextdate = StringUtils.getIsStringEqulesNull(map
                                    .get(CLRepeatTable.repDateTwo));
                            repeatSetChildEndUtils.setParentState(Integer.parseInt(mMap
                                    .get(ScheduleTable.schRepeatID)), repdate, nextdate, lastdate, map);
                        }
                    }
                    sharedPrefUtil.putString(context, ShareFile.USERFILE, ShareFile.SCHID, mMap.get(ScheduleTable.schID));
                    loadData(4, mMap.get(ScheduleTable.schID));

                    QueryAlarmData.writeAlarm(context.getApplicationContext());


                    Intent intentf = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
                    Bundle extras = new Bundle();
                    intentf.putExtras(extras);
                    context.sendBroadcast(intentf);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                dialog.dismiss();
            }
        });
        week.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                try {
                    updateFocusStateSch(mMap, ScheduleTable.schFocusState);
                    String date = inWeekUtils.AfterOneWeek(mMap.get(ScheduleTable.schDate));
                    App.getDBcApplication().updateScheduleDateData(id, date,
                            mMap.get(ScheduleTable.schTime));
                    App.getDBcApplication().updateSchReadData(
                            Integer.parseInt(mMap.get(ScheduleTable.schID)), 0);
                    App.getDBcApplication().updateSchRepeatLinkData(
                            Integer.parseInt(mMap.get(ScheduleTable.schID)), 0);
                    if ("".equals(mMap.get(ScheduleTable.schRepeatDate))
                            || "0".equals(mMap.get(ScheduleTable.schRepeatLink))) {

                    } else {
                        if (map != null) {
                            String repdate = mMap
                                    .get(ScheduleTable.schRepeatDate);
                            String lastdate = StringUtils.getIsStringEqulesNull(map
                                    .get(CLRepeatTable.repDateOne));
                            String nextdate = StringUtils.getIsStringEqulesNull(map
                                    .get(CLRepeatTable.repDateTwo));
                            repeatSetChildEndUtils.setParentState(Integer.parseInt(mMap
                                    .get(ScheduleTable.schRepeatID)), repdate, nextdate, lastdate, map);
                        }
                    }
                    sharedPrefUtil.putString(context, ShareFile.USERFILE, ShareFile.SCHID, mMap.get(ScheduleTable.schID));
                    loadData(4, mMap.get(ScheduleTable.schID));

                    QueryAlarmData.writeAlarm(context.getApplicationContext());


                    Intent intentf = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
                    Bundle extras = new Bundle();
                    intentf.putExtras(extras);
                    context.sendBroadcast(intentf);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                dialog.dismiss();
            }
        });
        month.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                try {
                    updateFocusStateSch(mMap, ScheduleTable.schFocusState);
                    String date = inWeekUtils.AfterOneMonth(mMap.get(ScheduleTable.schDate));
                    App.getDBcApplication().updateScheduleDateData(id, date,
                            mMap.get(ScheduleTable.schTime));
                    App.getDBcApplication().updateSchReadData(
                            Integer.parseInt(mMap.get(ScheduleTable.schID)), 0);
                    App.getDBcApplication().updateSchRepeatLinkData(
                            Integer.parseInt(mMap.get(ScheduleTable.schID)), 0);
                    if (!"".equals(mMap.get(ScheduleTable.schRepeatDate))
                            || !"0".equals(mMap.get(ScheduleTable.schRepeatLink))) {
                        if (map != null) {
                            String repdate = mMap
                                    .get(ScheduleTable.schRepeatDate);
                            String lastdate = StringUtils.getIsStringEqulesNull(map
                                    .get(CLRepeatTable.repDateOne));
                            String nextdate = StringUtils.getIsStringEqulesNull(map
                                    .get(CLRepeatTable.repDateTwo));
                            repeatSetChildEndUtils.setParentState(Integer.parseInt(mMap
                                    .get(ScheduleTable.schRepeatID)), repdate, nextdate, lastdate, map);
                        }
                    }
                    sharedPrefUtil.putString(context, ShareFile.USERFILE,
                            ShareFile.SCHID, mMap.get(ScheduleTable.schID));
                    sharedPrefUtil.putString(context, ShareFile.USERFILE,
                            ShareFile.SCHID, mMap.get(ScheduleTable.schID));
                    loadData(4, mMap.get(ScheduleTable.schID));

                    QueryAlarmData.writeAlarm(context
                            .getApplicationContext());


                    Intent intentf = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
                    Bundle extras = new Bundle();
                    intentf.putExtras(extras);
                    context.sendBroadcast(intentf);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                dialog.dismiss();
            }
        });


        if ("0".equals(mMap.get(ScheduleTable.schIsImportant))) {
//            important_image.setBackground(getResources().getDrawable(R.mipmap.anniu_zhongyao_hui));
            important.setText("设为重要");
        } else {
//            important_image.setBackground(getResources().getDrawable(R.mipmap.anniu_zhongyao_lv));
            important.setText("取消重要");
        }

        //重要
        important.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if ("0".equals(mMap.get(ScheduleTable.schIsImportant))) {
//                    important_image.setBackground(getResources().getDrawable(R.mipmap.anniu_zhongyao_lv));
                    important.setText("取消重要");
                    mMap.put(ScheduleTable.schIsImportant, "1");
                    App.getDBcApplication().updatImportant(1, mMap.get(ScheduleTable.schID));
                } else {
//                    important_image.setBackground(getResources().getDrawable(R.mipmap.anniu_zhongyao_hui));
                    important.setText("设为重要");
                    App.getDBcApplication().updatImportant(0, mMap.get(ScheduleTable.schID));
                    mMap.put(ScheduleTable.schIsImportant, "0");
                }
                try {
                    loadData(2, mMap.get(ScheduleTable.schID));
                    adapter.notifyDataSetChanged();
                    QueryAlarmData.writeAlarm(context.getApplicationContext());

                } catch (Exception e) {
                    e.printStackTrace();
                }
                dialog.dismiss();

            }
        });


        //分类
        fenlei.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                try {
                    CalenderFlagDialog calenderFlagDialog = new CalenderFlagDialog(context, R.style.dialog_translucent,
                            getWindowManager(), mMap.get(ScheduleTable.schID), colorname, "");
                    calenderFlagDialog.setCallBack(new CalenderFlagDialog.CallBack() {
                        @Override
                        public void reminderEditTime(String name, String id) {
//                            loadData(true);
                            loadData(2, mMap.get(ScheduleTable.schID));
                        }
                    });
                    calenderFlagDialog.show();
                } catch (Exception e) {
                    e.printStackTrace();
                }
                dialog.dismiss();
            }
        });


        /*****第二页****/
        final TextView copy_one = viewTwo.findViewById(R.id.copy_one);
        TextView delete = viewTwo.findViewById(R.id.delete);
        TextView shitinglings = viewTwo.findViewById(R.id.shitinglings);
        delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                sharedPrefUtil.putString(context,
                        ShareFile.USERFILE,
                        ShareFile.DELETETYPE,
                        "1");
                try {
                    if (Integer.valueOf(mList.get(position).get(ScheduleTable.schcRecommendId)) > 0
                            && Integer.valueOf(mList.get(position).get(ScheduleTable.schAID)) == 0) {
                        if (!mList.get(position).get(ScheduleTable.schRepeatID).equals("0")) {
                            sharedPrefUtil.putString(context,
                                    ShareFile.USERFILE,
                                    ShareFile.UPLOADTYPE,
                                    "1");
                            deleteCalender(mMap, 0, position);
                        } else {
                            sharedPrefUtil.putString(context,
                                    ShareFile.USERFILE,
                                    ShareFile.UPLOADTYPE,
                                    "0");
                            alertDeleteDialog(mMap, 0, position);
                        }

                    } else {
                        sharedPrefUtil.putString(context,
                                ShareFile.USERFILE,
                                ShareFile.UPLOADTYPE,
                                "1");
                        deleteCalender(mMap, 0, position);
                    }

                } catch (Exception e) {
                    e.printStackTrace();
                }
                Intent intentd = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
                Bundle extrasd = new Bundle();
                intentd.putExtras(extrasd);
                context.sendBroadcast(intentd);
                dialog.dismiss();
            }
        });


        try {
            fileDescriptor = context.getAssets().openFd(
                    mMap.get(ScheduleTable.schRingCode)
                            + ".mp3");
            mediaPlayer.setDataSource(
                    fileDescriptor.getFileDescriptor(),
                    fileDescriptor.getStartOffset(),
                    fileDescriptor.getLength());
            mediaPlayer.prepare();
        } catch (Exception e) {
            e.printStackTrace();
        }
        st_ll.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mediaPlayer != null && mediaPlayer.isPlaying()) {
                    mediaPlayer.stop();
                    mediaPlayer.reset();
                    try {
                        AssetFileDescriptor fileDescriptor = context
                                .getAssets().openFd(
                                        mMap.get(ScheduleTable.schRingCode)
                                                + ".mp3");
                        mediaPlayer.setDataSource(
                                fileDescriptor.getFileDescriptor(),
                                fileDescriptor.getStartOffset(),
                                fileDescriptor.getLength());
                        mediaPlayer.prepare();
                        mediaPlayer.start();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                } else {
                    mediaPlayer.start();
                }
            }
        });
        //试听铃声
        shitinglings.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mediaPlayer != null && mediaPlayer.isPlaying()) {
                    mediaPlayer.stop();
                    mediaPlayer.reset();
                    try {
                        AssetFileDescriptor fileDescriptor = context
                                .getAssets().openFd(mMap.get(ScheduleTable.schRingCode) + ".mp3");
                        mediaPlayer.setDataSource(
                                fileDescriptor.getFileDescriptor(),
                                fileDescriptor.getStartOffset(),
                                fileDescriptor.getLength());
                        mediaPlayer.prepare();
                        mediaPlayer.start();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                } else {
                    mediaPlayer.start();
                }

            }
        });
        //复制文本
        copy_content.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ClipboardManager cm = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
                // 将文本内容放到系统剪贴板里。
                cm.setText(mMap.get(ScheduleTable.schContent));
                Toast.makeText(context, "已复制", Toast.LENGTH_SHORT).show();
                dialog.dismiss();
            }
        });
        copy_one.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ClipboardManager cm = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
                // 将文本内容放到系统剪贴板里。
                cm.setText(mMap.get(ScheduleTable.schContent));
                initRiliDiaLog(copy_one, mMap, true);
                dialog.dismiss();
            }
        });
        final ImageView yd1 = more_pop_menu.findViewById(R.id.yd1);
        final ImageView yd2 = more_pop_menu.findViewById(R.id.yd2);

        viewList.add(viewOne);

        if (!mMap.get(ScheduleTable.schSourceType).equals("3")
                && !mMap.get(ScheduleTable.schSourceType).equals("4")
                && !mMap.get(ScheduleTable.schSourceType).equals("5")) {
            viewList.add(viewTwo);
        } else {
            yd1.setVisibility(View.GONE);
            yd2.setVisibility(View.GONE);
        }

        ViewAdapter viewAdapter = new ViewAdapter(viewList);
        myViewPager.setAdapter(viewAdapter);


        myViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                if (!mMap.get(ScheduleTable.schSourceType).equals("3")
                        && !mMap.get(ScheduleTable.schSourceType).equals("4")
                        && !mMap.get(ScheduleTable.schSourceType).equals("5")) {
                    yd1.setBackground(getResources().getDrawable(R.drawable.calender_new_detail_yd1));
                    yd2.setBackground(getResources().getDrawable(R.drawable.calender_new_detail_yd1));
                    if (position == 0) {
                        yd1.setBackground(getResources().getDrawable(R.drawable.calender_new_detail_yd2));
                    }
                    if (position == 1) {
                        yd2.setBackground(getResources().getDrawable(R.drawable.calender_new_detail_yd2));
                    }
                }
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }


    private void detail(Map<String, String> mMap, Intent intent, int position) {
        if (mList.get(position).get(ScheduleTable.schSourceType).toString().equals("3")
                || mList.get(position).get(ScheduleTable.schSourceType).toString().equals("4")
                || mList.get(position).get(ScheduleTable.schSourceType).toString().equals("5")) {

            App.getDBcApplication().updateReadState(Integer.valueOf(mList.get(position).get(ScheduleTable.schID)), 2);
            MainActivity.instance.loadCount();
            Intent taskintent = new Intent(context, NewSixTaskDetailActivity.class);
            taskintent.putExtra("ID", mList.get(position).get(ScheduleTable.ID));
            taskintent.putExtra("schID", mList.get(position).get(ScheduleTable.schID));
            taskintent.putExtra("schSourceDesc", mList.get(position).get(ScheduleTable.schSourceDesc));
            taskintent.putExtra("schSourceType", mList.get(position).get(ScheduleTable.schSourceType));
            taskintent.putExtra("schImagePath", mList.get(position).get(ScheduleTable.schImagePath));
            taskintent.putExtra("schSourceType", mList.get(position).get(ScheduleTable.schSourceType));
            taskintent.putExtra("schCreateTime", mList.get(position).get(ScheduleTable.schCreateTime));
            taskintent.putExtra("schDate", mList.get(position).get(ScheduleTable.schDate));
            taskintent.putExtra("schTime", mList.get(position).get(ScheduleTable.schTime));
            taskintent.putExtra("schDisplayTime", mList.get(position).get(ScheduleTable.schDisplayTime));
            taskintent.putExtra("schIsPostpone", mList.get(position).get(ScheduleTable.schIsPostpone));
            taskintent.putExtra("schcRecommendName", mList.get(position).get(ScheduleTable.schcRecommendName));
            taskintent.putExtra("schContent", mList.get(position).get(ScheduleTable.schContent));
            taskintent.putExtra("schcRecommendId", mList.get(position).get(ScheduleTable.schcRecommendId));
            taskintent.putExtra("schIsEnd", mList.get(position).get(ScheduleTable.schIsEnd));
            taskintent.putExtra("schImagePath", mList.get(position).get(ScheduleTable.schImagePath));
            taskintent.putExtra("schRemark1", StringUtils.getIsStringEqulesNull(mList.get(position).get(ScheduleTable.schRemark1)));
            taskintent.putExtra("schRemark4", StringUtils.getIsStringEqulesNull(mList.get(position).get(ScheduleTable.schRemark4)));
            taskintent.putExtra("schRemark5", StringUtils.getIsStringEqulesNull(mList.get(position).get(ScheduleTable.schRemark5)));
            startActivityForResult(taskintent, 600);
        } else if (mList.get(position).get(ScheduleTable.schSourceType).toString().equals("2")) {
            App.getDBcApplication().updateReadState(Integer.valueOf(mList.get(position).get(ScheduleTable.schID)), 2);
            MainActivity.instance.loadCount();
            if (Integer.valueOf(mList.get(position).get(ScheduleTable.schcRecommendId)) >= 0 && StringUtils.getIsStringEqulesNull(mList.get(position).get(ScheduleTable.schRemark1)).equals("1")) {
                Intent taskintent = new Intent(context, NewSixTaskDetailActivity.class);
                taskintent.putExtra("ID", mList.get(position).get(ScheduleTable.ID));
                taskintent.putExtra("schID", mList.get(position).get(ScheduleTable.schID));
                taskintent.putExtra("schSourceDesc", mList.get(position).get(ScheduleTable.schSourceDesc));
                taskintent.putExtra("schImagePath", mList.get(position).get(ScheduleTable.schImagePath));
                taskintent.putExtra("schSourceType", mList.get(position).get(ScheduleTable.schSourceType));
                taskintent.putExtra("schCreateTime", mList.get(position).get(ScheduleTable.schCreateTime));
                taskintent.putExtra("schDate", mList.get(position).get(ScheduleTable.schDate));
                taskintent.putExtra("schTime", mList.get(position).get(ScheduleTable.schTime));
                taskintent.putExtra("schDisplayTime", mList.get(position).get(ScheduleTable.schDisplayTime));
                taskintent.putExtra("schIsPostpone", mList.get(position).get(ScheduleTable.schIsPostpone));
                taskintent.putExtra("schcRecommendName", mList.get(position).get(ScheduleTable.schcRecommendName));
                taskintent.putExtra("schContent", mList.get(position).get(ScheduleTable.schContent));
                taskintent.putExtra("schcRecommendId", mList.get(position).get(ScheduleTable.schcRecommendId));
                taskintent.putExtra("schIsEnd", mList.get(position).get(ScheduleTable.schIsEnd));
                taskintent.putExtra("schImagePath", mList.get(position).get(ScheduleTable.schImagePath));
                taskintent.putExtra("schRemark1", StringUtils.getIsStringEqulesNull(mList.get(position).get(ScheduleTable.schRemark1)));
                taskintent.putExtra("schRemark4", StringUtils.getIsStringEqulesNull(mList.get(position).get(ScheduleTable.schRemark4)));
                taskintent.putExtra("schRemark5", StringUtils.getIsStringEqulesNull(mList.get(position).get(ScheduleTable.schRemark5)));
                startActivityForResult(taskintent, 600);
            } else {
                Intent cintent = new Intent(context, CalenderNoteEditActivity.class);
                cintent.putExtra("lingshengnames", mList.get(position).get(ScheduleTable.schRingDesc));
                cintent.putExtra("lingshengcode", mList.get(position).get(ScheduleTable.schRingCode));
                cintent.putExtra("schTime", mList.get(position).get(ScheduleTable.schTime));
                cintent.putExtra("schDate", mList.get(position).get(ScheduleTable.schDate));
                cintent.putExtra("schIsAlarm", mList.get(position).get(ScheduleTable.schIsAlarm));
                cintent.putExtra("schBeforeTime", mList.get(position).get(ScheduleTable.schBeforeTime));
                cintent.putExtra("schDisplayTime", mList.get(position).get(ScheduleTable.schDisplayTime));
                cintent.putExtra("schIsPostpone", mList.get(position).get(ScheduleTable.schIsPostpone));
                cintent.putExtra("content", mList.get(position).get(ScheduleTable.schContent));
                cintent.putExtra("schSourceDesc", mList.get(position).get(ScheduleTable.schSourceDesc));
                cintent.putExtra("schImagePath", mList.get(position).get(ScheduleTable.schImagePath));
                cintent.putExtra("schID", mList.get(position).get(ScheduleTable.schID));
                cintent.putExtra("schIsEnd", mList.get(position).get(ScheduleTable.schIsEnd));
                cintent.putExtra("schRepeatID", mList.get(position).get(ScheduleTable.schRepeatID));
                cintent.putExtra("schRemark1", StringUtils.getIsStringEqulesNull(mList.get(position).get(ScheduleTable.schRemark1)));
                startActivityForResult(cintent, 600);
            }
        } else {
            if (Integer.valueOf(mList.get(position).get(ScheduleTable.schcRecommendId)) > 0
                    && Integer.valueOf(mList.get(position).get(ScheduleTable.schAID)) == 0) {
                if (!mList.get(position).get(ScheduleTable.schRepeatID).equals("0")) {
                    if (Integer.valueOf(mList.get(position).get(ScheduleTable.schcRecommendId)) >= 0 && StringUtils.getIsStringEqulesNull(mList.get(position).get(ScheduleTable.schRemark1)).equals("1")) {
                        Intent taskintent = new Intent(context, NewSixTaskDetailActivity.class);
                        taskintent.putExtra("ID", mList.get(position).get(ScheduleTable.ID));
                        taskintent.putExtra("schID", mList.get(position).get(ScheduleTable.schID));
                        taskintent.putExtra("schSourceDesc", mList.get(position).get(ScheduleTable.schSourceDesc));
                        taskintent.putExtra("schImagePath", mList.get(position).get(ScheduleTable.schImagePath));
                        taskintent.putExtra("schSourceType", mList.get(position).get(ScheduleTable.schSourceType));
                        taskintent.putExtra("schCreateTime", mList.get(position).get(ScheduleTable.schCreateTime));
                        taskintent.putExtra("schDate", mList.get(position).get(ScheduleTable.schDate));
                        taskintent.putExtra("schTime", mList.get(position).get(ScheduleTable.schTime));
                        taskintent.putExtra("schDisplayTime", mList.get(position).get(ScheduleTable.schDisplayTime));
                        taskintent.putExtra("schIsPostpone", mList.get(position).get(ScheduleTable.schIsPostpone));
                        taskintent.putExtra("schcRecommendName", mList.get(position).get(ScheduleTable.schcRecommendName));
                        taskintent.putExtra("schContent", mList.get(position).get(ScheduleTable.schContent));
                        taskintent.putExtra("schcRecommendId", mList.get(position).get(ScheduleTable.schcRecommendId));
                        taskintent.putExtra("schIsEnd", mList.get(position).get(ScheduleTable.schIsEnd));
                        taskintent.putExtra("schImagePath", mList.get(position).get(ScheduleTable.schImagePath));
                        taskintent.putExtra("schRemark1", StringUtils.getIsStringEqulesNull(mList.get(position).get(ScheduleTable.schRemark1)));
                        taskintent.putExtra("schRemark4", StringUtils.getIsStringEqulesNull(mList.get(position).get(ScheduleTable.schRemark4)));
                        taskintent.putExtra("schRemark5", StringUtils.getIsStringEqulesNull(mList.get(position).get(ScheduleTable.schRemark5)));
                        startActivityForResult(taskintent, 600);
                    } else {
                        Intent cintent = new Intent(context, CalenderNoteEditActivity.class);
                        cintent.putExtra("lingshengnames", mList.get(position).get(ScheduleTable.schRingDesc));
                        cintent.putExtra("lingshengcode", mList.get(position).get(ScheduleTable.schRingCode));
                        cintent.putExtra("schTime", mList.get(position).get(ScheduleTable.schTime));
                        cintent.putExtra("schDate", mList.get(position).get(ScheduleTable.schDate));
                        cintent.putExtra("schIsAlarm", mList.get(position).get(ScheduleTable.schIsAlarm));
                        cintent.putExtra("schBeforeTime", mList.get(position).get(ScheduleTable.schBeforeTime));
                        cintent.putExtra("schDisplayTime", mList.get(position).get(ScheduleTable.schDisplayTime));
                        cintent.putExtra("schIsPostpone", mList.get(position).get(ScheduleTable.schIsPostpone));
                        cintent.putExtra("content", mList.get(position).get(ScheduleTable.schContent));
                        cintent.putExtra("schSourceDesc", mList.get(position).get(ScheduleTable.schSourceDesc));
                        cintent.putExtra("schImagePath", mList.get(position).get(ScheduleTable.schImagePath));
                        cintent.putExtra("schID", mList.get(position).get(ScheduleTable.schID));
                        cintent.putExtra("schIsEnd", mList.get(position).get(ScheduleTable.schIsEnd));
                        cintent.putExtra("schRepeatID", mList.get(position).get(ScheduleTable.schRepeatID));
                        cintent.putExtra("schRemark1", StringUtils.getIsStringEqulesNull(mList.get(position).get(ScheduleTable.schRemark1)));
                        startActivityForResult(cintent, 600);
                    }
                } else {
                    if (!mList.get(position).get(ScheduleTable.schSourceDesc).isEmpty()) {
                        boolean isRead = false;
                        if (application.isRead(mMap.get(ScheduleTable.schID)) == -1) {
                            //新清单
                            isRead = true;
                        }

                        App.getDBcApplication().updateReadState(Integer.valueOf(mList.get(position).get(ScheduleTable.schID)), 2);
                        App.getDBcApplication().updateSchSourceDescSpare(mList.get(position).get(ScheduleTable.schID));
                        MainActivity.instance.loadCount();
                        NoteTitleDetailBean.TDelListBean bean = App.getDBcApplication().getOneNoteTitlesData(userid, mList.get(position).get(ScheduleTable.schSourceDesc), true);
                        if (bean.titles != null) {
                            intent = new Intent(context, NoteEditActivity.class);
                            intent.putExtra("qdlistenter", false);
                            intent.putExtra("titleid", "" + bean.titleId);
                            intent.putExtra("path", "" + bean.imgPath);
                            intent.putExtra("id", bean.id);
                            intent.putExtra("title", bean.titles);
                            intent.putExtra("ltype", bean.ltype + "");
                            intent.putExtra("styles", bean.styles);
                            intent.putExtra("copys", bean.copys);
                            intent.putExtra("remark", bean.remark);
                            intent.putExtra("remark1", bean.remark1);
                            intent.putExtra("openState", bean.openState);
                            intent.putExtra("type", 0);
                            startActivityForResult(intent, 100);
                        } else {
                            Intent intentfx = new Intent(context, QDFXDetailActivity.class);
                            intentfx.putExtra("title", mList.get(position).get(ScheduleTable.schContent));
                            intentfx.putExtra("titleId", mList.get(position).get(ScheduleTable.schSourceDesc));
                            intentfx.putExtra("path", "");
                            intentfx.putExtra("goodNum", "0");
                            intentfx.putExtra("redNum", "0");
                            intentfx.putExtra("name", mList.get(position).get(ScheduleTable.schcRecommendName));
                            intentfx.putExtra("time", mList.get(position).get(ScheduleTable.schCreateTime));
                            intentfx.putExtra("num", "0");
                            intentfx.putExtra("uid", mList.get(position).get(ScheduleTable.schcRecommendId));
                            intentfx.putExtra("stylee", 0);
                            if (mMap.get(ScheduleTable.schSourceType).equals("1")) {
                                intentfx.putExtra("type", 5);
                            } else {
                                intentfx.putExtra("type", 2);
                            }
                            if (isRead) {
                                intentfx.putExtra("isRead", 1);
                            }
                            startActivityForResult(intentfx, 100);
                        }
                    } else {
                        updateFrendsPostState(mList.get(position).get(ScheduleTable.schID));
                        App.getDBcApplication().updateReadState1(Integer.parseInt(mList.get(position).get(ScheduleTable.schID)));
                        Intent intent1 = new Intent(context, FrendLyActivity.class);
                        intent1.putExtra("types", 1);

                        MySchBean mySchBean = new MySchBean();
                        mySchBean.schID = mMap.get(ScheduleTable.schID);
                        mySchBean.schContent = mMap.get(ScheduleTable.schContent);
                        mySchBean.schDate = mMap.get(ScheduleTable.schDate);
                        mySchBean.schTime = mMap.get(ScheduleTable.schTime);
                        mySchBean.schIsAlarm = mMap.get(ScheduleTable.schIsAlarm);
                        mySchBean.schBeforeTime = mMap.get(ScheduleTable.schBeforeTime);
                        mySchBean.schDisplayTime = mMap.get(ScheduleTable.schDisplayTime);
                        mySchBean.schIsPostpone = mMap.get(ScheduleTable.schIsPostpone);
                        mySchBean.schIsImportant = mMap.get(ScheduleTable.schIsImportant);
                        mySchBean.schColorType = mMap.get(ScheduleTable.schColorType);
                        mySchBean.schIsEnd = mMap.get(ScheduleTable.schIsEnd);
                        mySchBean.schCreateTime = mMap.get(ScheduleTable.schCreateTime);
                        mySchBean.schTags = mMap.get(ScheduleTable.schTags);
                        mySchBean.schSourceType = mMap.get(ScheduleTable.schSourceType);
                        mySchBean.schSourceDesc = mMap.get(ScheduleTable.schSourceDesc);
                        mySchBean.schSourceDescSpare = mMap
                                .get(ScheduleTable.schSourceDescSpare);
                        mySchBean.schRepeatID = mMap.get(ScheduleTable.schRepeatID);
                        mySchBean.schRepeatDate = mMap.get(ScheduleTable.schRepeatDate);
                        mySchBean.schUpdateTime = mMap.get(ScheduleTable.schUpdateTime);
                        mySchBean.schUpdateState = mMap.get(ScheduleTable.schUpdateState);
                        mySchBean.schOpenState = mMap.get(ScheduleTable.schOpenState);
                        mySchBean.schRepeatLink = mMap.get(ScheduleTable.schRepeatLink);
                        mySchBean.schRingDesc = mMap.get(ScheduleTable.schRingDesc);
                        mySchBean.schRingCode = mMap.get(ScheduleTable.schRingCode);
                        mySchBean.schcRecommendName = mMap
                                .get(ScheduleTable.schcRecommendName);
                        mySchBean.schRead = mMap.get(ScheduleTable.schRead);
                        intent1.putExtra("bean", mySchBean);
                        intent1.putExtra("schFriendID", mMap.get(ScheduleTable.schcRecommendId));
                        startActivityForResult(intent1, 100);
                    }
                }
            } else {
                if (!mList.get(position).get(ScheduleTable.schSourceDesc).isEmpty()) {
                    boolean isRead = false;
                    if (application.isRead(mMap.get(ScheduleTable.schID)) == -1) {
                        //新清单
                        isRead = true;
                    }
                    App.getDBcApplication().updateReadState(Integer.valueOf(mList.get(position).get(ScheduleTable.schID)), 2);
                    App.getDBcApplication().updateSchSourceDescSpare(mList.get(position).get(ScheduleTable.schID));
                    MainActivity.instance.loadCount();
                    NoteTitleDetailBean.TDelListBean bean = App.getDBcApplication().getOneNoteTitlesData(userid, mList.get(position).get(ScheduleTable.schSourceDesc), true);
                    if (bean.titles != null) {
                        intent = new Intent(context, NoteEditActivity.class);
                        intent.putExtra("qdlistenter", false);
                        intent.putExtra("titleid", "" + bean.titleId);
                        intent.putExtra("path", "" + bean.imgPath);
                        intent.putExtra("id", bean.id);
                        intent.putExtra("title", bean.titles);
                        intent.putExtra("ltype", bean.ltype + "");
                        intent.putExtra("styles", bean.styles);
                        intent.putExtra("copys", bean.copys);
                        intent.putExtra("remark", bean.remark);
                        intent.putExtra("remark1", bean.remark1);
                        intent.putExtra("openState", bean.openState);
                        intent.putExtra("type", 0);
                        startActivityForResult(intent, 100);
                    } else {
                        Intent intentfx = new Intent(context, QDFXDetailActivity.class);
                        intentfx.putExtra("title", mList.get(position).get(ScheduleTable.schContent));
                        intentfx.putExtra("titleId", mList.get(position).get(ScheduleTable.schSourceDesc));
                        intentfx.putExtra("path", "");
                        intentfx.putExtra("goodNum", "0");
                        intentfx.putExtra("redNum", "0");
                        intentfx.putExtra("name", mList.get(position).get(ScheduleTable.schcRecommendName));
                        intentfx.putExtra("time", mList.get(position).get(ScheduleTable.schCreateTime));
                        intentfx.putExtra("num", "0");
                        if (mMap.get(ScheduleTable.schSourceType).equals("1")) {
                            intentfx.putExtra("type", 5);
                        } else {
                            intentfx.putExtra("type", 2);
                        }
                        if (isRead) {
                            intentfx.putExtra("isRead", 1);
                        }
                        intentfx.putExtra("uid", mList.get(position).get(ScheduleTable.schcRecommendId));
                        intentfx.putExtra("stylee", 0);
                        startActivityForResult(intentfx, 100);
                    }
                } else {
                    App.getDBcApplication().updateReadState(Integer.valueOf(mList.get(position).get(ScheduleTable.schID)), 2);
                    MainActivity.instance.loadCount();
                    if (Integer.valueOf(mList.get(position).get(ScheduleTable.schcRecommendId)) >= 0 && StringUtils.getIsStringEqulesNull(mList.get(position).get(ScheduleTable.schRemark1)).equals("1")) {
                        Intent taskintent = new Intent(context, NewSixTaskDetailActivity.class);
                        taskintent.putExtra("ID", mList.get(position).get(ScheduleTable.ID));
                        taskintent.putExtra("schID", mList.get(position).get(ScheduleTable.schID));
                        taskintent.putExtra("schSourceDesc", mList.get(position).get(ScheduleTable.schSourceDesc));
                        taskintent.putExtra("schImagePath", mList.get(position).get(ScheduleTable.schImagePath));
                        taskintent.putExtra("schSourceType", mList.get(position).get(ScheduleTable.schSourceType));
                        taskintent.putExtra("schCreateTime", mList.get(position).get(ScheduleTable.schCreateTime));
                        taskintent.putExtra("schDate", mList.get(position).get(ScheduleTable.schDate));
                        taskintent.putExtra("schTime", mList.get(position).get(ScheduleTable.schTime));
                        taskintent.putExtra("schDisplayTime", mList.get(position).get(ScheduleTable.schDisplayTime));
                        taskintent.putExtra("schIsPostpone", mList.get(position).get(ScheduleTable.schIsPostpone));
                        taskintent.putExtra("schcRecommendName", mList.get(position).get(ScheduleTable.schcRecommendName));
                        taskintent.putExtra("schContent", mList.get(position).get(ScheduleTable.schContent));
                        taskintent.putExtra("schcRecommendId", mList.get(position).get(ScheduleTable.schcRecommendId));
                        taskintent.putExtra("schIsEnd", mList.get(position).get(ScheduleTable.schIsEnd));
                        taskintent.putExtra("schImagePath", mList.get(position).get(ScheduleTable.schImagePath));
                        taskintent.putExtra("schRemark1", StringUtils.getIsStringEqulesNull(mList.get(position).get(ScheduleTable.schRemark1)));
                        taskintent.putExtra("schRemark4", StringUtils.getIsStringEqulesNull(mList.get(position).get(ScheduleTable.schRemark4)));
                        taskintent.putExtra("schRemark5", StringUtils.getIsStringEqulesNull(mList.get(position).get(ScheduleTable.schRemark5)));
                        startActivityForResult(taskintent, 600);
                    } else {
                        Intent cintent = new Intent(context, CalenderNoteEditActivity.class);
                        cintent.putExtra("lingshengnames", mList.get(position).get(ScheduleTable.schRingDesc));
                        cintent.putExtra("lingshengcode", mList.get(position).get(ScheduleTable.schRingCode));
                        cintent.putExtra("schTime", mList.get(position).get(ScheduleTable.schTime));
                        cintent.putExtra("schDate", mList.get(position).get(ScheduleTable.schDate));
                        cintent.putExtra("schIsAlarm", mList.get(position).get(ScheduleTable.schIsAlarm));
                        cintent.putExtra("schBeforeTime", mList.get(position).get(ScheduleTable.schBeforeTime));
                        cintent.putExtra("schDisplayTime", mList.get(position).get(ScheduleTable.schDisplayTime));
                        cintent.putExtra("schIsPostpone", mList.get(position).get(ScheduleTable.schIsPostpone));
                        cintent.putExtra("content", mList.get(position).get(ScheduleTable.schContent));
                        cintent.putExtra("schSourceDesc", mList.get(position).get(ScheduleTable.schSourceDesc));
                        cintent.putExtra("schImagePath", mList.get(position).get(ScheduleTable.schImagePath));
                        cintent.putExtra("schID", mList.get(position).get(ScheduleTable.schID));
                        cintent.putExtra("schIsEnd", mList.get(position).get(ScheduleTable.schIsEnd));
                        cintent.putExtra("schRepeatID", mList.get(position).get(ScheduleTable.schRepeatID));
                        cintent.putExtra("schRemark1", StringUtils.getIsStringEqulesNull(mList.get(position).get(ScheduleTable.schRemark1)));
                        startActivityForResult(cintent, 600);
                    }
                }
            }
        }
    }

    /**
     * app日程同步下行修改好友信息和留言
     */
    public void updateFrendsPostState(final String cid) {

        StringRequest stringRequest = new StringRequest(Method.POST, URLConstants.HOST + "/appFrends_updateFrendsPostState.do",
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String result) {
                        if (!TextUtils.isEmpty(result)) {
                            try {
                                if (responseCode(result)) {
                                    //TODO  同步成功
                                } else {
//                                    updateFrendsPostState(cid);
                                }
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                    }

                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {
                Log.d("TAG", "error:" + volleyError.toString());
            }
        }) {
            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                Map<String, String> map = new HashMap<>();
                map.put("uId", userid);
                map.put("cId", cid);
                return map;
            }
        };
        stringRequest.setTag("findLyNewNum");
        stringRequest.setRetryPolicy(new DefaultRetryPolicy(100000, 1, 1.0f));
        App.queues.add(stringRequest);
    }

    public boolean responseCode(String response) throws JSONException {
        int status = 0;
        JSONObject jsonObject = new JSONObject(response);
        int msg = jsonObject.getInt("status");
        return status == msg;
    }

    class ViewAdapter extends PagerAdapter {
        private List<View> viewList;//数据源

        public ViewAdapter(List<View> viewList) {
            this.viewList = viewList;
        }

        @Override
        public int getCount() {
            return viewList.size();
        }

        @Override
        public boolean isViewFromObject(View view, Object object) {
            return view == object;
        }

        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            container.addView(viewList.get(position));
            return viewList.get(position);
        }
    }


    /******日历*****/
    int[] solartime = new int[25];
    boolean isLeap = false;
    boolean isRed = false;
    ArrayList<HashMap<String, String>> data;
    String today;
    int temp_day;
    int temp_month;
    int temp_year;

    int to_day;
    int to_month;
    int to_year;
    int standard_day;
    int standard_month;
    String ToMonth = "01";
    int standard_year;
    String holiday = "";
    String curDate = "";

    int sourse;//
    String dateTime = "";// 日期
    private TextView title, today_tv;

    MyLinearLayout dataLinear;
    Handler handlerrili;
    LinearLayout.LayoutParams mLayoutParamss = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.MATCH_PARENT);

    /**
     * 加载数据
     */
    private void loadDatarili() {
        GenData(true, curDate);
        GenView();
    }

    private void initRiliDiaLog(final TextView date_tv, final Map<String, String> mMap, final boolean isCopyCalender) {
        final Dialog dialog = new Dialog(context, R.style.dialog_translucent);
        Window window = dialog.getWindow();
        WindowManager.LayoutParams params = window.getAttributes();// 获取LayoutParams
        window.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL);
        window.setAttributes(params);// 设置生效

        LayoutInflater fac = LayoutInflater.from(context);
        View more_pop_menu = fac.inflate(R.layout.dialog_calender_rili, null);
        dialog.setCanceledOnTouchOutside(true);
        dialog.setContentView(more_pop_menu);
        params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        params.width = getWindowManager().getDefaultDisplay().getWidth();
        dialog.show();
        if (mMap == null) {
            ToMonth = DateUtil.formatDateMMDD(new Date());
            Today = DateUtil.formatDateMMDD(new Date());
        } else {
            ToMonth = mMap.get(ScheduleTable.schDate).substring(5, 7);
            Today = mMap.get(ScheduleTable.schDate).substring(8, mMap.get(ScheduleTable.schDate).length());//2017-01-01
        }

        today_tv = (TextView) more_pop_menu.findViewById(R.id.today);
        dataLinear = (MyLinearLayout) more_pop_menu.findViewById(R.id.datalinear);
        title = (TextView) more_pop_menu.findViewById(R.id.title);
        dataLinear.setBackgroundColor(Color.WHITE);
        today_tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                curDate = DateUtil.formatDate(new Date());// new Date()为获取当前系统时间
                loadDatarili();
            }
        });
        more_pop_menu.findViewById(R.id.lastmonth).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (standard_month == 1) {
                    standard_month = 12;
                    standard_year--;
                } else {
                    standard_month--;
                }
                GenData(false, curDate);
                GenView();
                title.setText(standard_year + "年" + standard_month + "月");
                dataLinear.startAnimation(AnimationUtils.loadAnimation(context, R.anim.right_in));

            }
        });
        more_pop_menu.findViewById(R.id.nextmonth).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (standard_month == 12) {
                    standard_month = 1;
                    standard_year++;
                } else {
                    standard_month++;
                }
                GenData(false, curDate);
                GenView();
                title.setText(standard_year + "年" + standard_month + "月");
                dataLinear.startAnimation(AnimationUtils.loadAnimation(context, R.anim.left_in));

            }
        });
        handlerrili = new Handler() {
            public void handleMessage(Message msg) {
                if (msg == null) {
                    return;
                }
                switch (msg.what) {
                    case 0:
                        if (standard_month == 1) {
                            standard_month = 12;
                            standard_year--;
                        } else {
                            standard_month--;
                        }
                        GenData(false, curDate);
                        GenView();
                        title.setText(standard_year + "年" + standard_month + "月");
                        dataLinear.startAnimation(AnimationUtils.loadAnimation(context, R.anim.right_in));
                        break;

                    case 1:
                        if (standard_month == 12) {
                            standard_month = 1;
                            standard_year++;
                        } else {
                            standard_month++;
                        }
                        GenData(false, curDate);
                        GenView();
                        title.setText(standard_year + "年" + standard_month + "月");
                        dataLinear.startAnimation(AnimationUtils.loadAnimation(context, R.anim.left_in));
                        break;

                    case 2:
                        standard_year--;
                        GenData(false, curDate);
                        GenView();
                        title.setText(standard_year + "年" + standard_month + "月");
                        dataLinear.startAnimation(AnimationUtils.loadAnimation(context, R.anim.down_in));
                        break;

                    case 3:
                        standard_year++;
                        GenData(false, curDate);
                        GenView();
                        title.setText(standard_year + "年" + standard_month + "月");
                        dataLinear.startAnimation(AnimationUtils.loadAnimation(context, R.anim.up_in));
                        break;

                    case 9:
                        if (mMap == null) {
                            dialogDaoqili(msg.obj + "");
                        } else {
                            if (isCopyCalender) {
                                int schID = App.getDBcApplication().getLocalId(-1, "ScheduleTable", ScheduleTable.schID);
                                App.getDBcApplication().copyCalnederNoteData(userid,
                                        mMap.get(ScheduleTable.schID),
                                        mMap.get(ScheduleTable.schSourceDesc),
                                        (msg.obj + "").split("\n")[0].replace("\"", ""));
                                Toast.makeText(context, "已复制", Toast.LENGTH_SHORT).show();
                                loadData(0, schID + "");

                            } else {
                                date_tv.setText(msg.obj + "");
                                int schID = App.getDBcApplication().getLocalId(-1, "ScheduleTable", ScheduleTable.schID);
                                sharedPrefUtil.putString(context, ShareFile.USERFILE, ShareFile.SCHID, schID + "");
                                App.getDBcApplication().updateSceduleDataDate(mMap.get(ScheduleTable.schID), (msg.obj + "").split("\n")[0].replace("\"", ""));
                                if (!mMap.get(ScheduleTable.schRepeatID).equals("0")) {
                                    App.getDBcApplication().updateSchuledRepeatTo(mMap.get(ScheduleTable.schID));
                                }
                                if (DateUtil.parseDate((msg.obj + "").split("\n")[0].replace("\"", "")).before(DateUtil.parseDate(DateUtil.formatDate(new Date())))) {
                                    if (mMap.get(ScheduleTable.schDisplayTime).equals("1") && mMap.get(ScheduleTable.schIsPostpone).equals("0")) {
                                        loadData(1, mMap.get(ScheduleTable.schID));
                                    }
                                } else {
                                    loadData(2, mMap.get(ScheduleTable.schID));
                                }

                            }
                            QueryAlarmData.writeAlarm(context.getApplicationContext());
                            Intent intentappwidget = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
                            Bundle extras = new Bundle();
                            intentappwidget.putExtras(extras);
                            context.sendBroadcast(intentappwidget);

                        }

                        dialog.dismiss();


                        break;

                    case 11:
                        Toast.makeText(context, "网络中断", Toast.LENGTH_LONG).show();
                        break;

                    case 12:
                        Toast.makeText(context, "服务器错误", Toast.LENGTH_LONG).show();
                        break;
                }
            }
        };
        dataLinear.setHandler(handlerrili);


        new LoadDataAsyncTask().execute();


    }

    class LoadDataAsyncTask extends AsyncTask<Void, Void, Void> {

        @Override
        protected Void doInBackground(Void... params) {
            return null;
        }

        @Override
        protected void onPostExecute(Void result) {
            super.onPostExecute(result);
//			dialog.dismiss();
            GenData(true, curDate);
            GenView();
        }

    }

    public ArrayList<HashMap<String, String>> GenData(boolean isfirst, String date) {
        if (!date.equals("") && isfirst) {
            data = new ArrayList<HashMap<String, String>>();
            to_year = Integer.parseInt(date.split("-")[0].toString());
            to_month = Integer.parseInt(date.split("-")[1].toString());
            to_day = Integer.parseInt(date.split("-")[2].toString());
            temp_day = to_day;
            temp_month = to_month;
            temp_year = to_year;
            standard_day = to_day;
            standard_month = to_month;
            standard_year = to_year;
            today = date;
            title.setText(standard_year + "年" + standard_month + "月");
        } else {
            if (isfirst) {
                data = new ArrayList<HashMap<String, String>>();
                Calendar c = Calendar.getInstance();
                c.setTimeInMillis(System.currentTimeMillis());
                to_year = c.get(Calendar.YEAR);
                to_month = c.get(Calendar.MONTH);
                to_day = c.get(Calendar.DAY_OF_MONTH);

                to_month++;
                temp_day = to_day;
                temp_month = to_month;
                temp_year = to_year;
                standard_day = to_day;
                standard_month = to_month;
                standard_year = to_year;

                today = to_year + "-"
                        + (to_month > 9 ? "" + to_month : "0" + to_month) + "-"
                        + (to_day > 9 ? "" + to_day : "0" + to_day);
                title.setText(standard_year + "年" + standard_month + "月");
            } else {
                data = new ArrayList<HashMap<String, String>>();
                temp_day = standard_day;
                temp_month = standard_month;
                temp_year = standard_year;

            }
        }
        HashMap<String, String> map = new HashMap<String, String>();
        map.put("day", temp_day + "");

        map.put("isMonth", "1"); // 1是本月
        String tempStrT = temp_year + "-"
                + (temp_month > 9 ? "" + temp_month : "0" + temp_month) + "-"
                + (temp_day > 9 ? "" + temp_day : "0" + temp_day);
        if ("".equals(StringUtils.getIsStringEqulesNull(tempStrT))) {
            tempStrT = today;
        }
        if (today.equals(tempStrT)) {
            map.put("isToday", "1"); // 1是今天
            map.put("time", today);
        } else {
            map.put("isToday", "0"); // 1是今天
            map.put("time", tempStrT);
        }
        try {
            if (CalHoliday(Integer.valueOf(temp_month
                    + (temp_day > 9 ? "" + temp_day : "0" + temp_day)))) {
                map.put("lunar", holiday);
            } else {
                map.put("lunar", CalendarChange.CalendarChange(tempStrT));
            }
            if (isRed) {
                map.put("isHoliday", "1"); // 1节日
                isRed = false;
            } else {
                map.put("isHoliday", "0"); // 1节日
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        data.add(map);
        for (int i = temp_day - 1; i > 0; i--) {
            String tempStr = temp_year + "-"
                    + (temp_month > 9 ? "" + temp_month : "0" + temp_month)
                    + "-" + (i > 9 ? "" + i : "0" + i);
            map = new HashMap<String, String>();
            map.put("day", i + "");
            map.put("time", tempStr);
            map.put("isToday", "0"); // 1是今天
            map.put("isMonth", "1"); // 1是本月
            try {
                if (CalHoliday(Integer.valueOf("" + temp_month
                        + (i > 9 ? "" + i : "0" + i)))) {
                    map.put("lunar", holiday);
                } else {
                    map.put("lunar", CalendarChange.CalendarChange(tempStr));
                }
                if (isRed) {
                    map.put("isHoliday", "1"); // 1节日
                    isRed = false;
                } else {
                    map.put("isHoliday", "0"); // 1节日
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            data.add(0, map);
        }
        int te_week = calWeek(temp_year, temp_month, 1);
        if (temp_month == 1) {
            temp_year--;
            temp_month = 12;
        } else {
            temp_month--;
        }
        calLeapYear(temp_year);
        if (temp_month == 4 || temp_month == 6 || temp_month == 9
                || temp_month == 11) {
            for (int i = 30; i > 30 - te_week; i--) {
                String tempStr = temp_year + "-"
                        + (temp_month > 9 ? "" + temp_month : "0" + temp_month)
                        + "-" + (i > 9 ? "" + i : "0" + i);
                map = new HashMap<String, String>();
                map.put("day", i + "");
                map.put("time", tempStr);
                map.put("isToday", "0"); // 是今天
                map.put("isMonth", "0"); // 1是本月
                try {
                    if (CalHoliday(Integer.valueOf("" + temp_month
                            + (i > 9 ? "" + i : "0" + i)))) {
                        map.put("lunar", holiday);
                    } else {
                        map.put("lunar", CalendarChange.CalendarChange(tempStr));
                    }
                    if (isRed) {
                        map.put("isHoliday", "1"); // 1节日
                        isRed = false;
                    } else {
                        map.put("isHoliday", "0"); // 1节日
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                data.add(0, map);
            }
        } else if (temp_month == 2) {
            if (isLeap) {
                for (int i = 29; i > 29 - te_week; i--) {
                    String tempStr = temp_year
                            + "-"
                            + (temp_month > 9 ? "" + temp_month : "0"
                            + temp_month) + "-"
                            + (i > 9 ? "" + i : "0" + i);
                    map = new HashMap<String, String>();
                    map.put("day", i + "");
                    map.put("time", tempStr);
                    map.put("isToday", "0"); // 1是今天
                    map.put("isMonth", "0"); // 1是本月
                    try {
                        if (CalHoliday(Integer.valueOf("" + temp_month
                                + (i > 9 ? "" + i : "0" + i)))) {
                            map.put("lunar", holiday);
                        } else {
                            map.put("lunar",
                                    CalendarChange.CalendarChange(tempStr));
                        }
                        if (isRed) {
                            map.put("isHoliday", "1"); // 1节日
                            isRed = false;
                        } else {
                            map.put("isHoliday", "0"); // 1节日
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    data.add(0, map);
                }
            } else {
                for (int i = 28; i > 28 - te_week; i--) {
                    String tempStr = temp_year
                            + "-"
                            + (temp_month > 9 ? "" + temp_month : "0"
                            + temp_month) + "-"
                            + (i > 9 ? "" + i : "0" + i);
                    map = new HashMap<String, String>();
                    map.put("day", i + "");
                    map.put("time", tempStr);
                    map.put("isToday", "0"); // 1是今天
                    map.put("isMonth", "0"); // 1是本月
                    try {
                        if (CalHoliday(Integer.valueOf("" + temp_month
                                + (i > 9 ? "" + i : "0" + i)))) {
                            map.put("lunar", holiday);
                        } else {
                            map.put("lunar",
                                    CalendarChange.CalendarChange(tempStr));
                        }
                        if (isRed) {
                            map.put("isHoliday", "1"); // 1节日
                            isRed = false;
                        } else {
                            map.put("isHoliday", "0"); // 1节日
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    data.add(0, map);
                }
            }
        } else {
            for (int i = 31; i > 31 - te_week; i--) {
                String tempStr = temp_year + "-"
                        + (temp_month > 9 ? "" + temp_month : "0" + temp_month)
                        + "-" + (i > 9 ? "" + i : "0" + i);
                map = new HashMap<String, String>();
                map.put("day", i + "");
                map.put("time", tempStr);
                map.put("isToday", "0"); // 1是今天
                map.put("isMonth", "0"); // 1是本月
                try {
                    if (CalHoliday(Integer.valueOf("" + temp_month
                            + (i > 9 ? "" + i : "0" + i)))) {
                        map.put("lunar", holiday);
                    } else {
                        map.put("lunar", CalendarChange.CalendarChange(tempStr));
                    }
                    if (isRed) {
                        map.put("isHoliday", "1"); // 1节日
                        isRed = false;
                    } else {
                        map.put("isHoliday", "0"); // 1节日
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                data.add(0, map);
            }
        }
        if (temp_month == 12) {
            temp_year++;
            temp_month = 1;
        } else {
            temp_month = temp_month + 1;
        }
        calLeapYear(temp_year);
        if (temp_month == 4 || temp_month == 6 || temp_month == 9
                || temp_month == 11) {
            for (int i = to_day + 1; i <= 30; i++) {
                String tempStr = temp_year + "-"
                        + (temp_month > 9 ? "" + temp_month : "0" + temp_month)
                        + "-" + (i > 9 ? "" + i : "0" + i);
                map = new HashMap<String, String>();
                map.put("day", i + "");
                map.put("time", tempStr);
                map.put("isToday", "0"); // 1是今天
                map.put("isMonth", "1"); // 1是本月
                try {
                    if (CalHoliday(Integer.valueOf("" + temp_month
                            + (i > 9 ? "" + i : "0" + i)))) {
                        map.put("lunar", holiday);
                    } else {
                        map.put("lunar", CalendarChange.CalendarChange(tempStr));
                    }
                    if (isRed) {
                        map.put("isHoliday", "1"); // 1节日
                        isRed = false;
                    } else {
                        map.put("isHoliday", "0"); // 1节日
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                data.add(map);
            }
        } else if (temp_month == 2) {
            if (isLeap) {
                for (int i = to_day + 1; i <= 29; i++) {
                    String tempStr = temp_year
                            + "-"
                            + (temp_month > 9 ? "" + temp_month : "0"
                            + temp_month) + "-"
                            + (i > 9 ? "" + i : "0" + i);
                    map = new HashMap<String, String>();
                    map.put("day", i + "");
                    map.put("time", tempStr);
                    map.put("isToday", "0"); // 是今天
                    map.put("isMonth", "1"); // 1是本月
                    try {
                        if (CalHoliday(Integer.valueOf("" + temp_month
                                + (i > 9 ? "" + i : "0" + i)))) {
                            map.put("lunar", holiday);
                        } else {
                            map.put("lunar",
                                    CalendarChange.CalendarChange(tempStr));
                        }
                        if (isRed) {
                            map.put("isHoliday", "1"); // 1节日
                            isRed = false;
                        } else {
                            map.put("isHoliday", "0"); // 1节日
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    data.add(map);
                }
            } else {
                for (int i = to_day + 1; i <= 28; i++) {
                    String tempStr = temp_year
                            + "-"
                            + (temp_month > 9 ? "" + temp_month : "0"
                            + temp_month) + "-"
                            + (i > 9 ? "" + i : "0" + to_day);
                    map = new HashMap<String, String>();
                    map.put("day", i + "");
                    map.put("time", tempStr);
                    map.put("isToday", "0"); // 是今天
                    map.put("isMonth", "1"); // 1是本月
                    try {
                        if (CalHoliday(Integer.valueOf("" + temp_month
                                + (i > 9 ? "" + i : "0" + i)))) {
                            map.put("lunar", holiday);
                        } else {
                            map.put("lunar",
                                    CalendarChange.CalendarChange(tempStr));
                        }
                        if (isRed) {
                            map.put("isHoliday", "1"); // 1节日
                            isRed = false;
                        } else {
                            map.put("isHoliday", "0"); // 1节日
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    data.add(map);
                }
            }
        } else {
            for (int i = to_day + 1; i <= 31; i++) {
                String tempStr = temp_year + "-"
                        + (temp_month > 9 ? "" + temp_month : "0" + temp_month)
                        + "-" + (i > 9 ? "" + i : "0" + i);
                map = new HashMap<String, String>();
                map.put("day", i + "");
                map.put("time", tempStr);
                map.put("isToday", "0"); // 是今天
                map.put("isMonth", "1"); // 1是本月
                try {
                    if (CalHoliday(Integer.valueOf("" + temp_month
                            + (i > 9 ? "" + i : "0" + i)))) {
                        map.put("lunar", holiday);
                    } else {
                        map.put("lunar", CalendarChange.CalendarChange(tempStr));
                    }
                    if (isRed) {
                        map.put("isHoliday", "1"); // 1节日
                        isRed = false;
                    } else {
                        map.put("isHoliday", "0"); // 1节日
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                data.add(map);
            }
        }
        if (temp_month >= 12) {
            temp_year++;
            temp_month = 1;
        } else {
            temp_month++;
        }
        int mm = data.size();
        for (int i = 1; i <= 42 - mm; i++) {
            String tempStr = temp_year + "-"
                    + (temp_month > 9 ? "" + temp_month : "0" + temp_month)
                    + "-" + (i > 9 ? "" + i : "0" + i);
            map = new HashMap<String, String>();
            map.put("day", i + "");
            map.put("time", tempStr);
            map.put("isToday", "0"); // 是今天
            map.put("isMonth", "0"); // 1是本月
            try {
                if (CalHoliday(Integer.valueOf("" + temp_month
                        + (i > 9 ? "" + i : "0" + i)))) {
                    map.put("lunar", holiday);
                } else {
                    map.put("lunar", CalendarChange.CalendarChange(tempStr));
                }
                if (isRed) {
                    map.put("isHoliday", "1"); // 1节日
                    isRed = false;
                } else {
                    map.put("isHoliday", "0"); // 1节日
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            data.add(map);
        }
        return data;
    }

    public boolean CalHoliday(int t) {
        boolean is = false;
        switch (t / 100) {
            case 2:
                if (t == solartime[0]) {
                    holiday = "立春";
                    is = true;
                } else if (t == solartime[1]) {
                    holiday = "雨水";
                    is = true;
                }
                break;
            case 3:
                if (t == solartime[2]) {
                    holiday = "惊蛰";
                    is = true;
                } else if (t == solartime[3]) {
                    holiday = "春分";
                    is = true;
                }
                break;
            case 4:
                if (t == solartime[4]) {
                    holiday = "清明";
                    is = true;
                } else if (t == solartime[5]) {
                    holiday = "谷雨";
                    is = true;
                }
                break;
            case 5:
                if (t == solartime[6]) {
                    holiday = "立夏";
                    is = true;
                } else if (t == solartime[7]) {
                    holiday = "小满";
                    is = true;
                }
                break;
            case 6:
                if (t == solartime[8]) {
                    holiday = "芒种";
                    is = true;
                } else if (t == solartime[9]) {
                    holiday = "夏至";
                    is = true;
                }
                break;
            case 7:
                if (t == solartime[10]) {
                    holiday = "小暑";
                    is = true;
                } else if (t == solartime[11]) {
                    holiday = "大暑";
                    is = true;
                }
                break;
            case 8:
                if (t == solartime[12]) {
                    holiday = "立秋";
                    is = true;
                } else if (t == solartime[13]) {
                    holiday = "处暑";
                    is = true;
                }
                break;
            case 9:
                if (t == solartime[14]) {
                    holiday = "白露";
                    is = true;
                } else if (t == solartime[15]) {
                    holiday = "秋分";
                    is = true;
                }
                break;
            case 10:
                if (t == solartime[16]) {
                    holiday = "寒露";
                    is = true;
                } else if (t == solartime[17]) {
                    holiday = "霜降";
                    is = true;
                }
                break;
            case 11:
                if (t == solartime[18]) {
                    holiday = "立冬";
                    is = true;
                } else if (t == solartime[19]) {
                    holiday = "小雪";
                    is = true;
                }
                break;
            case 12:
                if (t == solartime[20]) {
                    holiday = "大雪";
                    is = true;
                } else if (t == solartime[21]) {
                    holiday = "冬至";
                    is = true;
                }
                break;
            case 1:
                if (t == solartime[22]) {
                    holiday = "小寒";
                    is = true;
                } else if (t == solartime[23]) {
                    holiday = "大寒";
                    is = true;
                }
                break;
        }
        switch (t) {
            case 101:
                holiday = "元旦";
                isRed = true;
                is = true;
                break;
            case 214:
                holiday = "情人节";
                is = true;
                break;
            case 308:
                holiday = "妇女节";
                is = true;
                break;
            case 312:
                holiday = "植树节";
                is = true;
                break;
            case 315:
                holiday = "消费日";
                is = true;
                break;
            case 401:
                holiday = "愚人节";
                is = true;
                break;
            // case 407:
            // holiday="卫生日";
            // is=true;
            // break;
            case 501:
                holiday = "劳动节";
                is = true;
                break;
            case 504:
                holiday = "青年节";
                is = true;
                break;
            // case 512:
            // holiday="护士节";
            // is=true;
            // break;
            // case 513:
            // holiday="助残日";
            // is=true;
            // break;

            case 601:
                holiday = "儿童节";
                is = true;
                break;
            case 605:
                holiday = "世界环境日";
                is = true;
                break;
            case 701:
                holiday = "建党节";
                is = true;
                break;
            case 801:
                holiday = "建军节";
                is = true;
                break;
            case 910:
                holiday = "教师节";
                is = true;
                break;
            case 1001:
                holiday = "国庆节";
                is = true;
                break;
            case 1225:
                holiday = "圣诞节";
                is = true;
                break;
            default:
                // is=false;
                break;
        }

        return is;
    }

    String Today = "";

    @SuppressWarnings("deprecation")
    public void GenView() {
        dataLinear.removeAllViews();
        mLayoutParamss.weight = 1;
        LayoutInflater lif = LayoutInflater.from(context);
        LinearLayout temp = new LinearLayout(context);
        int size = data.size();
        for (int i = 0; i < size; i++) {
            View convertView = lif.inflate(R.layout.gritem, null);
            TextView time = (TextView) convertView.findViewById(R.id.time);
            TextView lunar = (TextView) convertView.findViewById(R.id.lunar);
            TextView fraction = (TextView) convertView.findViewById(R.id.fraction);
            LinearLayout itemroot = (LinearLayout) convertView.findViewById(R.id.itemroot);
            HashMap<String, String> map = data.get(i);
            if ((i + 1) < size) {
                HashMap<String, String> map2 = data.get(i + 1);
                if (map2.get("lunar").equals("春节")) {
                    map.put("lunar", "除夕");
                }
            }
            String day = map.get("day");
            if (map.get("isMonth").equals("1"))// 1是本月
            {
                itemroot.setBackgroundDrawable(getResources().getDrawable(R.drawable.bg_riliactivity));
                if (map.get("isToday").equals("1"))// 1是今天
                {
                    time.setTextColor(getResources().getColor(R.color.sunday_txt));
                    lunar.setTextColor(getResources().getColor(R.color.sunday_txt));
//                    itemroot.setBackgroundDrawable(getResources().getDrawable(R.drawable.bg_riliactivity_jintian));
                } else {
                    itemroot.setBackgroundDrawable(getResources().getDrawable(R.drawable.bg_riliactivity));
                }
                if (ToMonth.equals(standard_month > 9 ? standard_month : "0" + standard_month)) {
                    if (Today.equals("" + (Integer.parseInt(day) > 9 ? day : "0" + day))) {
//                        time.setTextColor(getResources().getColor(R.color.sunday_txt));
//                        lunar.setTextColor(getResources().getColor(R.color.sunday_txt));
                        itemroot.setBackgroundDrawable(getResources().getDrawable(R.drawable.bg_riliactivity_jintian));
                    } else {
                        itemroot.setBackgroundDrawable(getResources().getDrawable(R.drawable.bg_riliactivity));
                    }
                }
//                int m = (i + 1) % 7;
//                if (m == 1 || m == 0) {
//                    time.setTextColor(Color.rgb(50, 79, 133));
//                }
                if (map.get("isHoliday").equals("1")) // 节日
                {
                    time.setTextColor(Color.RED);
                }
                itemroot.setTag(R.id.calendar_index, "1");//0其他,1是本月
            } else {
                time.setTextColor(getResources().getColor(R.color.othermonth_txt));
                lunar.setTextColor(getResources().getColor(R.color.othermonth_txt));
                itemroot.setBackgroundDrawable(getResources().getDrawable(R.drawable.bg_riliactivity));
                itemroot.setTag(R.id.calendar_index, "0");
            }

            String datestr = standard_year + "-" +
                    (standard_month > 9 ? standard_month : "0" + standard_month) + "-" +
                    (day.length() > 1 ? day : "0" + day);
            if (map.get("isMonth").equals("1")) {// 1是本月
                if (App.getDBcApplication().queryISNOTHOLIDAY(datestr).equals("1")) {//休息
                    fraction.setText("休");
                    fraction.setTextColor(getResources().getColor(R.color.sunday_txt));
                } else if (App.getDBcApplication().queryISNOTHOLIDAY(datestr).equals("2")) {//上班
                    fraction.setText("班");
                    fraction.setTextColor(getResources().getColor(R.color.title0));
                } else {
                    fraction.setVisibility(View.GONE);
                }
            }
            if (!map.get("isMonth").equals("1")) {
                time.setVisibility(View.GONE);
                fraction.setVisibility(View.GONE);
                lunar.setVisibility(View.GONE);
            }
            time.setText(day);
            lunar.setText(map.get("lunar"));
            itemroot.setTag(day);
            itemroot.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    String day = v.getTag().toString();
                    // 0其他,1是本月
                    String calendar_index = v.getTag(R.id.calendar_index)
                            .toString();
                    if ("1".equals(calendar_index)) {
                        String dateTime = Integer.toString(standard_year)
                                + "-"
                                + (standard_month > 9 ? "" + standard_month
                                : "0" + standard_month) + "-"
                                + (Integer.parseInt(day) > 9 ? day : "0" + day);
                        Message message = new Message();
                        message.what = 9;
                        message.obj = "\"" + dateTime + "\"\n设置日期";
                        Today = dateTime;
                        handlerrili.sendMessage(message);
                    }
                }
            });
            if ((i + 1) % 7 != 0) {
                temp.addView(convertView, mLayoutParamss);
            } else {
                if (i != 0) {
                    temp.addView(convertView, mLayoutParamss);
                    dataLinear.addView(temp, mLayoutParamss);
                    temp = new LinearLayout(context);
                }
            }
        }
    }

    /*
     * 基姆拉尔森计算公式 QgW4jIbx W= (d+2*m+3*(m+1)/5+y+y/4-y/100+y/400) mod 7 /
     *
     * d 天 m 月 y 年 1月2月换算为去年的13 14月计算
     *
     * 基姆拉尔森计算公式的C#的实现 %NfbgJcL_ //y：年，m：月，d：日。在参数都只传入相应的整数
     */
    private int calWeek(int y, int m, int d) {
        int a = 7; // 用来保存计算得到的星期几的整数 Dz>v;%$S-
        if ((m == 1) || (m == 2))// 如果是一月或二月进行换算 uWKc .
        {
            m += 12;
            y--;
        }
        a = (d + 2 * m + 3 * (m + 1) / 5 + y + y / 4 - y / 100 + y / 400) % 7; // 得到的星期几的整数
        // 
        // 7ehs+GI
        a++;
        if (a == 7) {
            a = 0;
        }
        return a;
    }

    public void calLeapYear(int i) {
        if (i % 100 == 0) {
            if (i % 400 == 0) {
                isLeap = true;
            } else {
                isLeap = false;
            }
        } else {
            if (i % 4 == 0) {
                isLeap = true;
            } else {
                isLeap = false;
            }
        }
    }


    private void dialogDaoqili(final String date) {
        Today = "";
        final BaseDialog dialog = new BaseDialog(context, R.style.dialog_translucent);
        Window window = dialog.getWindow();
        WindowManager.LayoutParams params = window.getAttributes();// 获取LayoutParams
        window.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL);
        window.setAttributes(params);// 设置生效

        LayoutInflater fac = LayoutInflater.from(context);
        View view = fac.inflate(R.layout.activity_adddaoqiriactivity, null);
        dialog.setCanceledOnTouchOutside(true);
        dialog.setContentView(view);
        params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        params.width = getWindowManager().getDefaultDisplay().getWidth() - 30;

        InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);

        dialog.getWindow().setSoftInputMode(
                WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);

        TextView time = (TextView) view.findViewById(R.id.time);
        final EditText addeverytask_tv = (EditText) view.findViewById(R.id.addeverytask_tv);
        view.findViewById(R.id.copy).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ClipboardManager clipboardManager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
                if (clipboardManager.getText() != null) {
                    addeverytask_tv.setText(addeverytask_tv.getText().toString() + clipboardManager.getText().toString());
                    addeverytask_tv.setSelection(addeverytask_tv.getText().toString().length());
                }
            }
        });
        view.findViewById(R.id.save).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!addeverytask_tv.getText().toString().isEmpty()) {
                    try {
                        int schID = App.getDBcApplication().getLocalId(-1, "ScheduleTable", ScheduleTable.schID);
                        sharedPrefUtil.putString(context, ShareFile.USERFILE, ShareFile.SCHID, schID + "");
                        int dqr = Integer.valueOf(sharedPrefUtil.getString(context, ShareFile.USERFILE, ShareFile.DQRBEFORETIME, "4320"));
                        Calendar calender = Calendar.getInstance();
                        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
                        calender.setTime(simpleDateFormat.parse(date.substring(1, 11)));
                        calender.add(Calendar.DAY_OF_MONTH, -(dqr / 60 / 24));
                        Date date1 = calender.getTime();
                        String ndate = DateUtil.formatDateTimeSs(date1);
                        //计算时间小于今天
                        if (date1.before(DateUtil.parseDate(DateUtil.formatDate(new Date())))) {
                            ndate = DateUtil.formatDate(new Date());
                        }
                        App.getDBcApplication().insertScheduleData(addeverytask_tv.getText().toString() + " (到期日 " + date.substring(1, 11) + ")"
                                , ndate.substring(0, 10), DateUtil.formatDateTimeHm(new Date()), 1,
                                0, 1, 1, 0,
                                0, 0, DateUtil.formatDateTime(new Date()), "", 0,
                                "", "", 0, "", DateUtil.formatDateTime(new Date()),
                                1, 0, 0, "到点提醒", "g_001", "", 0, 0, 0, "",
                                "", 0, 0, -1, 0, "", "0", "0");
                        Toast.makeText(context, "创建成功,", Toast.LENGTH_LONG).show();
                        loadData(0, schID + "");
                        QueryAlarmData.writeAlarm(context.getApplicationContext());


                        Intent intentappwidget = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
                        Bundle extras = new Bundle();
                        intentappwidget.putExtras(extras);
                        context.sendBroadcast(intentappwidget);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    dialog.dismiss();
                } else {
                    Toast.makeText(context, "内容不能为空", Toast.LENGTH_SHORT).show();
                }

            }
        });
        dialog.setCallBack(new BaseDialog.CallBack() {
            @Override
            public void onTouchOutside() {
                if (!addeverytask_tv.getText().toString().isEmpty()) {
                    try {
                        int schID = App.getDBcApplication().getLocalId(-1, "ScheduleTable", ScheduleTable.schID);
                        sharedPrefUtil.putString(context, ShareFile.USERFILE, ShareFile.SCHID, schID + "");
                        int dqr = Integer.valueOf(sharedPrefUtil.getString(context, ShareFile.USERFILE, ShareFile.DQRBEFORETIME, "4320"));
                        Calendar calender = Calendar.getInstance();
                        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
                        calender.setTime(simpleDateFormat.parse(date.substring(1, 11)));
                        calender.add(Calendar.DAY_OF_MONTH, -(dqr / 60 / 24));
                        Date date1 = calender.getTime();
                        String ndate = DateUtil.formatDateTimeSs(date1);
                        //计算时间小于今天
                        if (date1.before(DateUtil.parseDate(DateUtil.formatDate(new Date())))) {
                            ndate = DateUtil.formatDate(new Date());
                        }
                        App.getDBcApplication().insertScheduleData(addeverytask_tv.getText().toString() + " (到期日 " + date.substring(1, 11) + ")",
                                ndate.substring(0, 10),
                                DateUtil.formatDateTimeHm(new Date()), 1,
                                0, 1, 1, 0,
                                0, 0, DateUtil.formatDateTime(new Date()), "", 0,
                                "", "", 0, "", DateUtil.formatDateTime(new Date()),
                                1, 0, 0, "到点提醒", "g_001", "", 0, 0, 0, "",
                                "", 0, 0, -1, 0, "", "0", "0");
                        loadData(0, schID + "");
                        QueryAlarmData.writeAlarm(context.getApplicationContext());


                        Intent intentappwidget = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
                        Bundle extras = new Bundle();
                        intentappwidget.putExtras(extras);
                        context.sendBroadcast(intentappwidget);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                dialog.dismiss();
            }
        });

        time.setText("到期日: " + date.substring(1, 11));

        imm.showSoftInput(addeverytask_tv, 0);

        dialog.show();

    }

    private void updateFocusStateSch(Map<String, String> mMap, String key) {
        try {
            Map<String, String> upMap = new HashMap<String, String>();
            upMap.put(key, "1");
            App.getDBcApplication().updateSchFocusState(upMap,
                    "where schID=" + mMap.get("schID"));
        } catch (NumberFormatException e) {
            e.printStackTrace();
        }
    }

    private void deleteCalender(Map<String, String> mMap, int type, final int position) {
        if (type == 0) {
            if (StringUtils.getIsStringEqulesNull(mMap.get(ScheduleTable.schRemark1)).equals("1")) {
                ShareUrlDelete(mMap, true);
            }
            if (Integer.parseInt(mMap.get(ScheduleTable.schID)) < 0) {
                if (schIDList != null && schIDList.size() > 0) {
                    for (int i = 0; i < schIDList.size(); i++) {
                        Object[] indexStr = schIDList.get(i).keySet().toArray();
                        String index = indexStr[0].toString();
                        if (Integer.parseInt(mMap.get(ScheduleTable.schID)) == Integer.parseInt(index)) {
                            mMap.put(ScheduleTable.schID, schIDList.get(i).get(index));
                            break;
                        }
                    }
                }
            }
            try {
                String deleteId = mMap.get(ScheduleTable.schID);
                App dbContextExtended = App.getDBcApplication();
                dbContextExtended.deleteScheduleLocalData(deleteId);
                if (mMap.get(ScheduleTable.schRemark1) != null && mMap.get(ScheduleTable.schRemark1).equals("1")) {
                    dbContextExtended.updateScheduleLocalDataschRemark3(deleteId);
                } else {
                    dbContextExtended.deleteScheduleLocalData(deleteId);
                }
                dbContextExtended.deleteSch(Integer.parseInt(deleteId));

                updateDeleteScheduleRead(mMap, ScheduleTable.schRead, ScheduleTable.schRepeatLink);
                updateFocusStateSch(mMap, ScheduleTable.schFocusState);
                QueryAlarmData.writeAlarm(context.getApplicationContext());
                if (Integer.valueOf(mMap.get(ScheduleTable.schRepeatID)) < 1) {
                    List<CalenderNoteBean.PageBean.ItemsBean> itemsBeanList =
                            App.getDBcApplication().getCalenderNoteDetailData(userid, mMap.get(ScheduleTable.schSourceDesc), false);
                    for (CalenderNoteBean.PageBean.ItemsBean bean : itemsBeanList) {
                        int state = App.getDBcApplication().getCalenderNoteDetailState(bean.titleId, userid, bean.id);
                        if (!mMap.get(ScheduleTable.schRemark1).equals("1")) {
                            App.getDBcApplication().deleteCalenderNoteDetail(bean.id, mMap.get(ScheduleTable.schSourceDesc), userid, state == 1);
                        }
                    }
                }
                loadData(1, mMap.get(ScheduleTable.schID));
                adapter.notifyDataSetChanged();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    private void updateDeleteScheduleRead(Map<String, String> mMap, String key,
                                          String key1) {
        try {
            String value = "0";
            Map<String, String> upMap = new HashMap<String, String>();
            if ("0".equals(mMap.get(key)))
                value = "0";
            else
                value = "0";
            upMap.put(key, value);
            upMap.put(key1, "2");
            App.getDBcApplication().updateScheduleData(upMap, "where schID=" + mMap.get("schID"));
            mMap.put(key, value);
        } catch (NumberFormatException e) {
            e.printStackTrace();
        }
    }

    private void ShareUrlDelete(final Map<String, String> mMap, boolean isMy) {
        try {
            final JSONObject data = new JSONObject();
            JSONArray timetable = new JSONArray();
            JSONObject json = new JSONObject();
            if (isMy) {
                json.put("updateState", 3);
                json.put("uid", "");
                json.put("puid", userid);
                json.put("pname", sharedPrefUtil.getString(ShareFile.USERNAME, ""));
            } else {
                json.put("updateState", 4);
                json.put("uid", userid);
                json.put("puid", mMap.get(ScheduleTable.schcRecommendId));
                json.put("pname", mMap.get(ScheduleTable.schcRecommendName));
            }
            json.put("ptitleimg", mMap.get(ScheduleTable.schImagePath));
            json.put("titleId", mMap.get(ScheduleTable.schSourceDesc));
            json.put("cdate", mMap.get(ScheduleTable.schDate));
            json.put("ctime", mMap.get(ScheduleTable.schTime));
            json.put("content", mMap.get(ScheduleTable.schContent));
            json.put("cisEnd", mMap.get(ScheduleTable.schIsEnd));
            json.put("cDisplayAlarm", mMap.get(ScheduleTable.schDisplayTime));
            json.put("cIsAlarm", mMap.get(ScheduleTable.schIsAlarm));
            json.put("cbefortime", mMap.get(ScheduleTable.schBeforeTime));
            json.put("cAlarmsound", mMap.get(ScheduleTable.schRingCode));
            json.put("cAlarmsoundDesc", mMap.get(ScheduleTable.schRingDesc));
            json.put("cPostpone", mMap.get(ScheduleTable.schIsPostpone));
            json.put("cImportant", mMap.get(ScheduleTable.schIsImportant));
            json.put("cscore", "0");
            json.put("changeTime", DateUtil.nowTime());
            json.put("createTime", DateUtil.nowTime());
            json.put("remark", "");
            json.put("remark1", "");
            json.put("remark2", "");
            json.put("remark3", "");
            json.put("remark4", "");
            json.put("remark5", "");
            timetable.put(json);
            data.put("timetable", timetable);


            StringRequest request4 = new StringRequest(Method.POST, URLConstants.同步临时表数据, new Response.Listener<String>() {
                @Override
                public void onResponse(String s) {
                }


            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError volleyError) {

                }
            }) {
                @Override
                protected Map<String, String> getParams() throws AuthFailureError {
                    Map<String, String> map = new HashMap<String, String>();
                    map.put("data", data.toString());
                    return map;
                }
            };
            request4.setTag("同步临时表数据");
            request4.setRetryPolicy(new DefaultRetryPolicy(5000, 1, 1.0f));
            App.getHttpQueues().add(request4);
        } catch (JSONException e) {
            e.printStackTrace();
        }

    }

    private void alertDeleteDialog(final Map<String, String> mMap,
                                   final int type, final int position) {
        final AlertDialog builder = new AlertDialog.Builder(context).create();
        builder.show();
        Window window = builder.getWindow();
        WindowManager.LayoutParams params = window.getAttributes();// 获取LayoutParams
        params.alpha = 0.92f;
        window.setAttributes(params);// 设置生效
        window.setContentView(R.layout.dialog_alterdelete);
        TextView delete_ok = (TextView) window.findViewById(R.id.delete_ok);
        delete_ok.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                builder.cancel();
                if (mMap.get(ScheduleTable.schSourceType).equals("4") || mMap.get(ScheduleTable.schSourceType).equals("5")) {
                    ShareUrlDelete(mMap, false);
                }
                deleteCalender(mMap, type, position);
            }
        });
        TextView delete_canel = (TextView) window.findViewById(R.id.delete_canel);
        delete_canel.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                builder.cancel();
            }
        });
        TextView delete_tv = (TextView) window.findViewById(R.id.delete_tv);
        if (type == 0) {
            delete_tv.setText("确定要删除此记事吗?");
        } else {
            delete_tv.setText("结束今天之前所有未结束的记事?");
        }

    }


    /**
     * 结束日程
     */
    private void deleteItem(final Map<String, String> mMap, final int position) {
        final AlertDialog builder = new AlertDialog.Builder(context)
                .create();

        builder.show();
        Window window = builder.getWindow();
        WindowManager.LayoutParams params = window.getAttributes();// 获取LayoutParams
        params.alpha = 0.92f;
        window.setAttributes(params);// 设置生效
        window.setContentView(R.layout.dialog_alterdelete);
        TextView delete_ok = (TextView) window.findViewById(R.id.delete_ok);
        TextView delete_canel = (TextView) window
                .findViewById(R.id.delete_canel);
        delete_canel.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                adapter.notifyDataSetChanged();
                builder.dismiss();
            }
        });
        TextView delete_tv = (TextView) window.findViewById(R.id.delete_tv);

        delete_tv.setText("确定要结束此日程吗?");

        delete_ok.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                endCalender(mMap, position);
                builder.dismiss();
            }
        });
    }

    private void endCalender(Map<String, String> mMap, int position) {
        try {
            if ("0".equals(mMap.get(ScheduleTable.schIsEnd))) {
                soundstate = sharedPrefUtil.getString(context,
                        ShareFile.USERFILE, ShareFile.ENDSOUNDSTATE,
                        "0");
                wakestate = sharedPrefUtil
                        .getString(context, ShareFile.USERFILE,
                                ShareFile.ENDWAKESTATE, "0");
                if ("0".equals(soundstate)) {
                    MediaPlayer mediaPlayer = mediaPlayer = new MediaPlayer();
                    AssetFileDescriptor fileDescriptor = context
                            .getAssets().openFd("complete.mp3");
                    mediaPlayer.setDataSource(
                            fileDescriptor.getFileDescriptor(),
                            fileDescriptor.getStartOffset(),
                            fileDescriptor.getLength());
                    mediaPlayer.prepare();
                    mediaPlayer.start();
                }
                if ("0".equals(wakestate)) {
                    long[] pattern = {100, 400}; // 停止 开启 停止 开启
                    vibrator.vibrate(pattern, -1); // 重复两次上面的pattern
                    // 如果只想震动一次，index设为-1
                }
            }
            if ("0".equals(mMap.get(ScheduleTable.schRepeatID))) {
                updateScheduleRead1(mMap, ScheduleTable.schRead);
            } else {
                updateScheduleRead2(mMap, ScheduleTable.schRead,
                        ScheduleTable.schRepeatLink);
            }
            MainActivity.instance.loadCount();
            updateScheduleIsEnd(mMap, ScheduleTable.schIsEnd, ScheduleTable.schUpdateState);
            updateSchClock(mMap, LocateAllNoticeTable.isEnd);
            QueryAlarmData.writeAlarm(context);
            sharedPrefUtil.putString(context, ShareFile.USERFILE, ShareFile.ENDUPDATETIME, DateUtil.formatDateTimeSs(new Date()));
            loadData(2, mMap.get(ScheduleTable.schID));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void updateScheduleIsEnd(Map<String, String> mMap, String key,
                                     String key1) {
        try {
            if ("1".equals(mMap.get(ScheduleTable.schRepeatLink)) || "3".equals(mMap.get(ScheduleTable.schRepeatLink))) {
                repeatSetChildEndUtils.setParentStateIsEnd(mMap);
            }
            String value = "0";
            Map<String, String> upMap = new HashMap<String, String>();
            if ("0".equals(mMap.get(key)))
                value = "1";
            else
                value = "0";
            upMap.put(key, value);
            if ("1".equals(mMap.get(ScheduleTable.schRepeatLink))
                    || "3".equals(mMap.get(ScheduleTable.schRepeatLink))) {
                upMap.put(key1, "0");
            } else {
                upMap.put(key1, "2");
            }
            App.getDBcApplication().updateScheduleData(upMap,
                    "where schID=" + mMap.get("schID"));
        } catch (Exception e) {
            e.printStackTrace();
        }
        loadData(2, mMap.get(ScheduleTable.schID));
    }

    private void updateScheduleRead1(Map<String, String> mMap, String key) {
        try {
            String value = "0";
            Map<String, String> upMap = new HashMap<String, String>();
            value = mMap.get(ScheduleTable.schRead);
            upMap.put(key, value);
            App.getDBcApplication().updateScheduleData1(upMap, "where schID=" + mMap.get("schID"));
            mMap.put(key, value);
        } catch (NumberFormatException e) {
            e.printStackTrace();
        }
    }

    private void updateScheduleRead2(Map<String, String> mMap, String key,
                                     String key1) {
        try {
            String value = "0";
            Map<String, String> upMap = new HashMap<String, String>();
            value = mMap.get(key);
            upMap.put(key, value);
            upMap.put(key1, "3");
            App.getDBcApplication().updateScheduleData(upMap,
                    "where schID=" + mMap.get("schID"));
        } catch (NumberFormatException e) {
            e.printStackTrace();
        }
    }

    private void updateSchClock(Map<String, String> mMap, String key) {
        try {
            String value = "0";
            String key1 = "";
            Map<String, String> upMap = new HashMap<String, String>();
            if (key.equals("isEnd")) {
                key1 = "schIsEnd";
            } else if (key.equals("postpone")) {
                key1 = "schIsPostpone";
            }
            if ("1".equals(mMap.get(key1)))
                value = "1";
            else
                value = "0";
            upMap.put(key, value);
            App.getDBcApplication().updateSchIsEnd(upMap,
                    "where schID=" + mMap.get("schID"));
        } catch (NumberFormatException e) {
            e.printStackTrace();
        }
    }
}
